练习7--Python判断一个句子是否为回文

什么是回文诗:
有这样一类数,他们可以顺着和倒着念都有韵味。
经典的诗有
潮随暗浪雪山倾,远浦渔舟钓月明。
桥对寺门松径小,槛当泉眼石波清。

知识点:字符串的索引和序列

while True:
	sentence = raw_input('input a sentence')
	if sentence == 'q' or sentence == 'Q':
		break
	elif sentence == sentence[::-1]:
		print 'This sentence is a palindrome'
	else:
		print 'This is a normal sentence'

输出如下:
在这里插入图片描述

发布了36 篇原创文章 · 获赞 65 · 访问量 2947

猜你喜欢

转载自blog.csdn.net/Miracle1203/article/details/102705302