From e6721afb22bf37fbe0ab125c7eef638caba8c73d Mon Sep 17 00:00:00 2001 From: Portfolio Date: Sun, 17 Nov 2024 22:56:14 +0530 Subject: [PATCH 1/2] Added a code that checks if a given input (phrase, word, or integer) is a palindrome --- strings/word_phrase_int_palindrome.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 strings/word_phrase_int_palindrome.py diff --git a/strings/word_phrase_int_palindrome.py b/strings/word_phrase_int_palindrome.py new file mode 100644 index 000000000..2271ce6cb --- /dev/null +++ b/strings/word_phrase_int_palindrome.py @@ -0,0 +1,12 @@ +def is_palindrome(input_value): + # Convert the input to a string and remove spaces and special characters (for phrases) + sanitized_value = ''.join(filter(str.isalnum, str(input_value))).lower() + + # Check if the sanitized string is equal to its reverse + return sanitized_value == sanitized_value[::-1] + +input_value = input("Enter a phrase, word, or number to check if it's a palindrome: ") +if is_palindrome(input_value): + print("The input is a palindrome.") +else: + print("The input is not a palindrome.") From 6145f97757be5bbc1aa4d4fc433c2e1038f3ed5c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 17 Nov 2024 17:34:44 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/word_phrase_int_palindrome.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/strings/word_phrase_int_palindrome.py b/strings/word_phrase_int_palindrome.py index 2271ce6cb..9cbb9884e 100644 --- a/strings/word_phrase_int_palindrome.py +++ b/strings/word_phrase_int_palindrome.py @@ -1,10 +1,11 @@ def is_palindrome(input_value): # Convert the input to a string and remove spaces and special characters (for phrases) - sanitized_value = ''.join(filter(str.isalnum, str(input_value))).lower() - + sanitized_value = "".join(filter(str.isalnum, str(input_value))).lower() + # Check if the sanitized string is equal to its reverse return sanitized_value == sanitized_value[::-1] + input_value = input("Enter a phrase, word, or number to check if it's a palindrome: ") if is_palindrome(input_value): print("The input is a palindrome.")