制作一个程序来检测一个单词是否是回文(忽略大写)



我在制作这个程序时遇到了麻烦,因为我不知道如何制作,所以程序会忽略大写。我用过.lower,但我想我插错了。

word=input("Give me a word to detect if it is a palindrome")
word=str(word)
if word.lower[::-1]=word :
print("That's a palindrome")
else:
print("Sorry this isn't a palindrome")

试试这个:

word=input("Give me a word to detect if it is a palindrome: ")
word_list = word.split()
for i in word_list:
if i.lower()[::-1]==i.lower() and len(i) > 1:
print("That's a palindrome")
else:
print("Sorry this isn't a palindrome")

这将检测所有的回文,如果你只想输入一个单词,请删除for循环。

最新更新