我在elif myanswer ==“1”:行上收到ELIF错误 它说语法错误然后指向elif的结尾。 感谢您的帮助,我真的很感激。
#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")
答案 0 :(得分:0)
elif
只能在if
语句之后使用。替换您的第一个elif
elif myanswer == "1"
带
if myanswer == "1":