1
a = input("输入一段话")
b = int(len(a)) #算出这段话的字数
c = int(len(a)/2)
print(b)
if b == 2 and a[0] == a[-1]:
print("是回文")
quit()
elif b == 3 and a[0] == a[-1]:
print("是回文")
quit()
elif b == c*2 and a[c] == a[c - 1]:
print("是回文")
elif b == c*2+1 and a[c] == a[-c -1]:
print("是回文")
2
s = input('输入一段话:')
if not s:
print('不要输入空字符串!')
s = input('请重新输入一个字符串:')
a = len(s)
i = 0
count = 1
while i <= (a/2):
if s[i] == s[a-i-1]:
count = 1 i += 1
else:
count = 0
break
if count == 1:
print('是回文')
else:
print('不是回文')
最后附赠一个装13大法
sen = input('请输入需要判断的语句:')
print('是回文') if sen.strip()==sen.strip()[::-1] else print('不是回文')