Python code to determine whether the given string is a palindrome or not.

3. Develop a python code to determine whether the given string is a palindrome or not a palindrome.

Answer:

Palindrome Check in Python

A palindrome is a word or phrase that reads the same forward and backward (like madam, 121, racecar).

Python Code:

text = input("Enter a string: ")

# Check if the string is equal to its reverse
if text == text[::-1]:
    print("Palindrome")
else:
    print("Not a palindrome")

Example:

Input: madam
Output: Palindrome

Input: hello
Output: Not a palindrome

Leave a Reply

Your email address will not be published. Required fields are marked *