Skip to content

Commit

Permalink
Create Palindrome_Checker.py
Browse files Browse the repository at this point in the history
 A simple script which checks if a given phrase is a Palindrome
  • Loading branch information
ekbalba authored Feb 22, 2018
1 parent f9573d0 commit 444917f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Palindrome_Checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.")

0 comments on commit 444917f

Please sign in to comment.