无效语法elif python

2024-09-28 21:49:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我在ELIF myanswer==“1”:行上得到一个ELIF错误 say的语法错误然后指向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") 

Tags: andthetoloopyoutrueheadtail