forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome_Checker.py
More file actions
23 lines (18 loc) · 805 Bytes
/
Palindrome_Checker.py
File metadata and controls
23 lines (18 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# AUTHOR: ekbalba
# DESCRIPTION: A simple script which checks if a given phrase is a Palindrome
# PALINDROME: A word, phrase, or sequence that reads the same backward as forward
samplePhrase = "A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal-Panama!"
givenPhrase = ""
phrase = ""
givenPhrase = input("\nPlease input a phrase:(Press ENTER to use the sample phrase) ")
if givenPhrase == "" or not givenPhrase.strip():
print("\nThe sample phrase is: {0}".format(samplePhrase))
phrase = samplePhrase
else:
phrase = givenPhrase
string = "".join(char.lower() for char in phrase if char.isalnum())
reversedString = "".join(reversed(string))
if string == reversedString:
print("\nWow!, The phrase is a Palindrome!")
else:
print("\nSorry, The given phrase is not a Palindrome.")