Skip to content

Added a code that checks if a given input (phrase, word, or integer) #12380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 13 additions & 0 deletions strings/word_phrase_int_palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def is_palindrome(input_value):
# Convert the input to a string and remove spaces and special characters (for phrases)

Check failure on line 2 in strings/word_phrase_int_palindrome.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

strings/word_phrase_int_palindrome.py:2:89: E501 Line too long (90 > 88)
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.")
Loading