Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions palindrome_checker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# palindrome_checker.py
def is_palindrome(s):
return s == s[::-1]
# Normalize the string: convert to lower case and filter out non-alphanumeric characters
normalized_s = ''.join(char.lower() for char in s if char.isalnum())

# Check if the normalized string is equal to its reverse
length = len(normalized_s)
for i in range(length // 2):
if normalized_s[i] != normalized_s[length - 1 - i]:
return False

return True

if __name__ == "__main__":
word = input("Enter a word: ")
print(f"{word} is a palindrome: {is_palindrome(word)}")
word = input("Enter a word or phrase: ")
if word.strip() == "":
print("You did not enter a valid string.")
else:
print(f"'{word}' is a palindrome: {is_palindrome(word)}")