Skip to content

Commit e6721af

Browse files
Added a code that checks if a given input (phrase, word, or integer) is a palindrome
1 parent e3bd772 commit e6721af

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def is_palindrome(input_value):
2+
# Convert the input to a string and remove spaces and special characters (for phrases)
3+
sanitized_value = ''.join(filter(str.isalnum, str(input_value))).lower()
4+
5+
# Check if the sanitized string is equal to its reverse
6+
return sanitized_value == sanitized_value[::-1]
7+
8+
input_value = input("Enter a phrase, word, or number to check if it's a palindrome: ")
9+
if is_palindrome(input_value):
10+
print("The input is a palindrome.")
11+
else:
12+
print("The input is not a palindrome.")

0 commit comments

Comments
 (0)