首页 > 解决方案 > Making a program to detect if a word is a palindrome (ignoring capitalization)

问题描述

I have trouble making this program because I don't know how to make it so the program will ignore capitalization. I used .lower but I think I'm inserting it wrong.

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")

标签: python

解决方案


尝试这个:

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 循环。


推荐阅读