forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A simple script which checks if a given phrase is a Palindrome
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |