Task: Write a Python program to input a string and check it for Palindrome or not.
The source code of Palindrome Program in Python
# Write a Python program to input # a string and check it for Palindrome # Author: www.EasyCodeBook.com s1=input("Enter string to check for Palindrome:") # get reversed string by string slicing s2 = s1[::-1] # chcek if origional and reversed strings are equal # then show Palindrome otherwise Not a Palindrome message if(s1 == s2): print("The string is a Palindrome") else: print("The string is not a Palindrome") # output # Enter string to check for Palindrome:mom # The string is a Palindrome
The output:
Enter string to check for Palindrome:hello python
The string is not a Palindrome
Another run may give:
Enter string to check for Palindrome:radar
The string is a Palindrome