Input a word and check if it is palindrome word or not using a function in Python
Function - Question 4
In this question, we will see how to input a word and check if it is palindrome word or not in Python programming using a function. To know more about function click on the function lesson.
Q4) Write a program in Python to input a word and check if it is palindrome word or not using a function. The function should return 1 if the word is palindrome else return 0.
A word is called palindrome if its reverse form is equal the original word.
Example: madam Reverse Form: madam
Program
def palindrome(str):
rev=str[::-1] # reverse the word using string slicing method
if rev==str:
return 1
return 0
# main program
s=input('Enter a String: ')
if palindrome(s)==1:
print('Palindrome Word')
else:
print('Not Palindrome Word')
Output
Enter a String: madam Palindrome Word