1 Star 0 Fork 0

dzc/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Palindrome_Checker.py 926 Bytes
一键复制 编辑 原始数据 按行查看 历史
shivam agarwal 提交于 2019-10-03 15:18 +08:00 . Update Palindrome_Checker.py
# 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_==True:
print("\nWow!, The phrase is a Palindrome!")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sdredboy/Python-1.git
git@gitee.com:sdredboy/Python-1.git
sdredboy
Python-1
Python-1
master

搜索帮助