From e18ab0ed902bb0ff3d168b99841e1c27d776d90f Mon Sep 17 00:00:00 2001 From: ZoyaQadeer Date: Sat, 19 Oct 2024 15:26:34 +0530 Subject: [PATCH] Update palindrome_checker.py --- palindrome_checker.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/palindrome_checker.py b/palindrome_checker.py index c0fdc30..9a22de8 100644 --- a/palindrome_checker.py +++ b/palindrome_checker.py @@ -1,7 +1,13 @@ # palindrome_checker.py + +import re + def is_palindrome(s): + # Normalize the string: lowercasing and removing non-alphanumeric characters + s = re.sub(r'[^a-zA-Z0-9]', '', s).lower() return s == s[::-1] if __name__ == "__main__": - word = input("Enter a word: ") - print(f"{word} is a palindrome: {is_palindrome(word)}") + word = input("Enter a word or phrase: ") + print(f"'{word}' is a palindrome: {is_palindrome(word)}") +