forked from ghostmkg/dsa-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.py
More file actions
23 lines (18 loc) · 981 Bytes
/
palindrome.py
File metadata and controls
23 lines (18 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def is_palindrome(text):
# Remove spaces and convert to lowercase for accurate comparison
cleaned = ''.join(char.lower() for char in text if char.isalnum())
return cleaned == cleaned[::-1]
print("Welcome to the Palindrome Checker!")
print("A palindrome is a word, number, or phrase that reads the same backward as forward.")
print("For example, 'Level', '12321', and 'A man a plan a canal Panama' are palindromes.")
print("---------------------------------------------------------------")
while True:
user_input = input("Enter any word, number, or phrase to check (or type 'exit' to quit): ")
if user_input.strip().lower() == 'exit':
print("Thank you for using the Palindrome Checker. Goodbye!")
break
if is_palindrome(user_input):
print(f"Yes! '{user_input}' is a palindrome.\n")
else:
print(f"No, '{user_input}' is not a palindrome.\n")
print("---------------------------------------------------------------")