From a75585392113fd1362b892ce8624f1ba2745a65c Mon Sep 17 00:00:00 2001 From: Eiman Tahir Date: Sun, 29 Mar 2026 09:24:07 +0500 Subject: [PATCH 1/4] Add files via upload --- 5-Working with Strings/exercise2.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 5-Working with Strings/exercise2.py diff --git a/5-Working with Strings/exercise2.py b/5-Working with Strings/exercise2.py new file mode 100644 index 0000000..7d14d63 --- /dev/null +++ b/5-Working with Strings/exercise2.py @@ -0,0 +1,9 @@ +def is_palindrome(text): + text = "".join(char.lower() for char in text if char.isalnum()) + return text == text[::-1] + +input_text = input("Enter a string: ") +if is_palindrome(input_text): + print(f'"{input_text}" is a palindrome.') +else: + print(f'"{input_text}" is not a palindrome.') \ No newline at end of file From aeb8985e0bb482978aa8b5ee277a77c546b9eecf Mon Sep 17 00:00:00 2001 From: Eiman Tahir Date: Sun, 29 Mar 2026 09:32:27 +0500 Subject: [PATCH 2/4] Update 5-Working with Strings/exercise2.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- 5-Working with Strings/exercise2.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/5-Working with Strings/exercise2.py b/5-Working with Strings/exercise2.py index 7d14d63..94bedb6 100644 --- a/5-Working with Strings/exercise2.py +++ b/5-Working with Strings/exercise2.py @@ -2,8 +2,9 @@ def is_palindrome(text): text = "".join(char.lower() for char in text if char.isalnum()) return text == text[::-1] -input_text = input("Enter a string: ") -if is_palindrome(input_text): - print(f'"{input_text}" is a palindrome.') -else: - print(f'"{input_text}" is not a palindrome.') \ No newline at end of file +if __name__ == "__main__": + input_text = input("Enter a string: ") + if is_palindrome(input_text): + print(f'"{input_text}" is a palindrome.') + else: + print(f'"{input_text}" is not a palindrome.') \ No newline at end of file From fb54a0548f6bece1d9165e3186ad6b1322db28ac Mon Sep 17 00:00:00 2001 From: Eiman Tahir Date: Sun, 29 Mar 2026 09:32:37 +0500 Subject: [PATCH 3/4] Update 5-Working with Strings/exercise2.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- 5-Working with Strings/exercise2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5-Working with Strings/exercise2.py b/5-Working with Strings/exercise2.py index 94bedb6..a429a08 100644 --- a/5-Working with Strings/exercise2.py +++ b/5-Working with Strings/exercise2.py @@ -1,5 +1,5 @@ def is_palindrome(text): - text = "".join(char.lower() for char in text if char.isalnum()) + text = "".join(char.casefold() for char in text if char.isalnum()) return text == text[::-1] if __name__ == "__main__": From da0a67c66e0cb9dad6981d0c5fe715ff478e812a Mon Sep 17 00:00:00 2001 From: Eiman Tahir Date: Sun, 29 Mar 2026 09:32:45 +0500 Subject: [PATCH 4/4] Update 5-Working with Strings/exercise2.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- 5-Working with Strings/exercise2.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/5-Working with Strings/exercise2.py b/5-Working with Strings/exercise2.py index a429a08..a121a2e 100644 --- a/5-Working with Strings/exercise2.py +++ b/5-Working with Strings/exercise2.py @@ -1,4 +1,10 @@ def is_palindrome(text): + """ + Return True if `text` is a palindrome after normalization. + + Normalization keeps only alphanumeric characters and compares + the result in a case-insensitive manner. + """ text = "".join(char.casefold() for char in text if char.isalnum()) return text == text[::-1]