Added a code that checks if a given input (phrase, word, or integer) is a palindrome

This commit is contained in:
Portfolio 2024-11-17 22:56:14 +05:30
parent e3bd7721c8
commit e6721afb22

View File

@ -0,0 +1,12 @@
def is_palindrome(input_value):
# Convert the input to a string and remove spaces and special characters (for phrases)
sanitized_value = ''.join(filter(str.isalnum, str(input_value))).lower()
# Check if the sanitized string is equal to its reverse
return sanitized_value == sanitized_value[::-1]
input_value = input("Enter a phrase, word, or number to check if it's a palindrome: ")
if is_palindrome(input_value):
print("The input is a palindrome.")
else:
print("The input is not a palindrome.")