我的elif语句中的语法无效,为什么会出现代码:
while correct_turns != len(word):
if correct_turns == len(word):
finish()
guess = input("Please guess a letter from above: ")
elif guess in word and not LettersUnused:
used_letter(guess,display,LettersUnused)
elif guess in word and LettersUnused:
correct(guess,display,correct_turns,LettersUnused)
elif guess in LettersUnused and not word:
incorrect(guess,display,LettersUnused)
elif guess not in LettersUnused:
used_letter(guess,display,LettersUnused)
elif len(guess)>1:
guess_word(guess)
答案 0 :(得分:2)
根据您的缩进,您的第一个elif
应该只是if
。无论如何elif
与第一个if
无关。
答案 1 :(得分:2)
您不需要初始if
,因为您的while
循环条件会阻止循环输入。
你无法继续'继续'一个if
块,中间有另一条线。将第一个elif
更改为if
以启动新块;您也可以删除其他if
语句,因为它永远不会执行。
while correct_turns != len(word):
guess = input("Please guess a letter from above: ")
if guess in word and not LettersUnused:
used_letter(guess,display,LettersUnused)
elif guess in word and LettersUnused:
correct(guess,display,correct_turns,LettersUnused)
elif guess in LettersUnused and not word:
incorrect(guess,display,LettersUnused)
elif guess not in LettersUnused:
used_letter(guess,display,LettersUnused)
elif len(guess)>1:
guess_word(guess)