python改错

来源:百度知道 编辑:UC知道 时间:2024/06/14 16:05:18
def palindrome(word):
w=0
wordlist=[]
sortlist=[]
if w==0:
wordlist.append(word[w])
w=w+1
if w==len(word):
sortlist.append(word[w])
w=w-1
if sortlist==wordlist:
print "True"
return word
else:
print "False"
word=raw_input("type in the word: ")
print palindrome(word)

请问这个哪里错了呢??为什么不output任何东西就自动关闭
帮我改对了.谢谢
问题题目: A palindrome is a word that reads the same both forward and backwards. Create a function called palindrome that takes a single word as a parameter and returns True if the word is a palindrome and False otherwise.

图:

用得着这么麻烦么??

def palindrome(word):
____s = word.replace(" ", "").lower()
____if s == s[::-1]:
_________return True
____else:
_________return False

word=raw_input("type in the word: ")
print palindrome(word)

少了循环。