diff --git a/palindrome_checker.py b/palindrome_checker.py index c0fdc30..249c1b9 100644 --- a/palindrome_checker.py +++ b/palindrome_checker.py @@ -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)}")