Python Exercise: Reverse a word
Python Conditional: Exercise-5 with Solution
Write a Python program that accepts a word from the user and reverses it.
# Prompt the user to input a word word = input("Input a word to reverse: ") # Iterate through the characters of the word in reverse order for char in range(len(word) - 1, -1, -1): # Print each character from the word in reverse order without a new line (end="") print(word[char], end="") # Print a new line to separate the reversed word from the next output print("\n")
Input a word to reverse: ecruoser3w w3resource
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join