Q. Write a Python function that checks whether a passed string is a palindrome or not.
Note: A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.
Answer =
def check(x) : if x[ -1 : - len(x) - 1 : - 1] == x: print ("String is a palindrome.") else : print ("String is not a palindrome ") string = input ("Enter a String :- ") check(string)
Output: -
If input is ‘madam’:-
Enter a String :- madam
String is a palindrome.
>>>
If input is ‘nurses’:-
Enter a String :- nurses
String is not a palindrome
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )