KnowledgeBoat Logo

Computer Science

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.

Python

Python Functions

1 Like

Answer

def is_palindrome(s):
    s = s.lower()
    return s == s[::-1]

input_string = input("Enter a string: ")
if is_palindrome(input_string):
    print(input_string, "is a palindrome.")
else:
    print(input_string, "is not a palindrome.")

Output

Enter a string: madam
madam is a palindrome.


Enter a string: nursesrun
nursesrun is a palindrome.


Enter a string: watermelon
watermelon is not a palindrome.

Answered By

1 Like


Related Questions