-2
我在elif myanswer ==“1”上收到ELIF错误:行 它说的语法错误然后指向elif的结尾。 感谢您的帮助,我真的很感激。无效语法elif python错误
#if statements to make the first scenario run
print(place1)
while not gameOver:
print(option1)
myanswer = getanswer()
elif myanswer == "1":
print("nothing happens, the dog just waits")
elif myanswer == "2":
print("You nobely decide to fight the dog.")
#if statements to make the second scenario run
print(place2)
while not (belly and head and tail):
print(option2)
myanswer = getanswer(["1","2","3","4"])
if myanswer == "1":
print("You scratched the dog on the head with your claws")
head = True
elif myanswer == "2":
print("You bite into the dog's soft belly")
belly = True
elif myanswer =="3":
print("You cut off the dog's tail with your razor sharp teeth")
tail = True
elif myanswer =="4":
print("You carefully retreat some steps away from the dog")
print(situation1) #return to the main loop
break # leave the dog loop
break # leave the dog loop and leave main loop
else:
# dog loop was leaved correctly
print("The dog bleeds from head, tail and belly and runs away."
"You are victorious! Congratulation, you have won the game")
gameOver = True #leave the dog loop correctly
elif myanswer == "3":
print("You run away, but the dog is faster than you and eats you whole!."
"The dog eat you. Game Over")
gameOver = True
print("Try again and thanks for playing")
变化的第一个'elif'到'if',因为你只能有一个'elif'是也有一个'if'声明。 https://docs.python.org/2/tutorial/controlflow.html – martijnn2008
因为它'elif'具有** no **尾随'if'条件,可以将其更改为'if'或添加一个'if'语句它上面。此外,您在相同的缩进级别使用2个'break'语句,并且不会按预期工作。 – ZdaR
你只能在if后写elif。第一个应该由'if'替换 –