forked from Ratna04priya/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome_Checker.py
32 lines (24 loc) · 919 Bytes
/
Palindrome_Checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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 == "":
print("\nThe sample phrase is: {0}".format(samplePhrase))
phrase = samplePhrase
else:
phrase = givenPhrase
phrase = phrase.lower()
length_ = len(phrase)
bol_ = True
# check using two pointers, one at beginning
# other at the end. Use only half of the list.
for items in range(length_//2):
if phrase[items] != phrase[length_ - 1 - items]:
print("\nSorry, The given phrase is not a Palindrome.")
bol_ = False
break
if bol_:
print("\nWow!, The phrase is a Palindrome!")