Exercise 24 

A palindrome is a word whose order of letters remains the same whether it is read from left to right or from right to left. For example: 'laval', 'radar,' sos' ... are palindromes. Write a program in Python that asks the user to enter a word and return it if it is a palindrome or not?

Solution

# Ask to type a string s
s = input("Type a string s : ")

# getting the reverse of the string s
s1 = s[::-1]

# try if the typed strins s is a palindrome
if(s1 == s):
print("The string : '",s," ' is a palindrome")
else:
print("The string : '",s," ' is not a palindrome")
Younes Derfoufi

Leave a Reply