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.
Pictorial Presentation:
Sample Solution:
Python Code:
# 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")
Sample Output:
Input a word to reverse: ecruoser3w w3resource
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to construct the following pattern, using a nested for loop.
Next: Write a Python program to count the number of even and odd numbers from a series of numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/python-conditional-exercise-5.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics