[英]cannot fix this “else” statement error
the second "else" statement gives a syntax error. 第二个“ else”语句给出语法错误。 I don't understand why.
我不明白为什么。 what is wrong with the code?
代码有什么问题? Pardon me, still a beginner
对不起,我还是个初学者
while True:
guess = input("Guess a letter or the whole word: ")
if guess == word:
print("Yaye, you've won and have saved my neck!")
break
else:
for letter in letters:
if letter in letters:
continue
else:
guesses -= 1
word_guess(guesses)
if guesses == 0:
break
You can see in the Python 3 flow control documentation an example of an if
statement. 您可以在Python 3 流程控制文档中看到
if
语句的示例。 It can only have one else
statement because that is what is run when all other cases ( if
and elif
) didn't match. 它只能有一条
else
语句,因为这是在所有其他情况( if
和elif
)不匹配时运行的语句。 When are you expecting the second else to run? 您预计何时还能运行其他设备?
As was pointed out in another answer, indentation in python matters . 正如另一个答案中指出的那样,python中的缩进很重要 。
Is this perhaps the indentation you are looking for? 这也许是您正在寻找的缩进吗?
while True:
guess = input("Guess a letter or the whole word: ")
if guess == word:
print("Yaye, you've won and have saved my neck!")
break
else:
for letter in letters:
if letter in letters:
continue
else:
guesses -= 1
word_guess(guesses)
if guesses == 0:
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.