Exercise 25

Write a program that asks the user to enter a word and return the opposite. Example if the user enters the word

python

, the program returns

nohtyp

.

Solution

# Ask user to enter a some string s
s = input("Enter a some string s : ")
# initializing reverse of the string s
reverse = ""

# Building the string s in a reversed way
for x in s:
reverse = x + reverse
print("The reverse of the string: ", s , " is : " , reverse)
Younes Derfoufi
my-courses.net

Leave a Reply