请解决错误

时间:2015-10-11 18:22:05

标签: python

File "<stdin>", line 63
    elif answerthree == "go to gas station":
       ^
SyntaxError: invalid syntax

未知错误。

我添加了while true:位,当我完成时,我得到了这个:

print "hello, and welcome to your world!"
print "are you ready?"
while True:   
        answerone = raw_input("yes or no?").lower()
        if answerone == "yes" or answerone == "y":
            break
            print "well fantastic! your at a crossroads you can go left or right..."
        while True:    
            answertwo = raw_input("left or right?").lower()
            if answertwo == "left" or answertwo == "l":
                break
                print "you got hit by a car your dead"
                print "gameover"
            elif answertwo == "right" or answertwo == "r":
                break   
                print "you see a gas station"
                print "but you also she something shiny in the sand"
            while True:    
                answerthree = raw_input("grab the shiny object or go to the gas station?").lower()
                if answerthree == "grab shiny object":
                    break
                    print "you found a GUN!"
                    print" but it only has"
                    from random import randint
                    bullets = (randint(2,9))
                    print bullets
                print "bullets"
                while True:    
                    answerfive = raw_input("do you continue to the gas station or go to a nearby building to sleep? type either gas station or sleep")
                    if answerfive == "sleep":
                        break
                        print " you went to a nearby building to sleep."
                    elif answerfive == "gas station":
                        break
                        print "on your way to the gas station you encounter enemys inside the building"
                    print "there are"
                    enemys = (randint(2,9))
                    print enemys
                    print "of them"
                while True:    
                    answersix = raw_input("do you try to shoot them with your gun or flee to a nearby building? type either shoot or flee")
                    if answersix == "shoot":
                        break
                        print " you go to shoot them"
                        if enemys>7:
                            print "when you went to attack you were overpowered by their numbers and died"
                            print "game over"
                        elif enemys<7:
                            print "you went to attack them and emerged victorious!"
                            bullets = bullets-enemys
                            if bullets<0:
                                bullets = 0
                            print "you now only have"
                            print bullets
                            print "left"
                        else:
                            print "error"
                    elif answersix == "flee":
                        break
                        print " you flee to a nearby building where you sleep for the night"
                    else:
                        print "you diddnt type anything!"
                elif answerthree == "go to gas station":
                    break
                    print "on your way to the gas station you encounter enemys inside the building"
                    print "there are"
                    enemys = (randint(2,9))
                    print enemys
                    print "of them"
                while True    
                    answerfour = raw_input("do you try to fight them with your fists or flee to a nearby building?")
                    if answerfour == "fight them":
                        break
                        print " you go to attack them"
                        if enemys>3:
                            print "when you went to attack you were overpowered by their numbers and died"
                            print "game over"
                        elif enemys<3:
                            print "you went to attack them and emerged victorious!"
                        else:
                            print "error"
                    elif answerfour == "flee":
                        break
                        print " you flee to a nearby building where you sleep for the night"
                    else:
                        print "you diddnt type anything!"
                else:
                    print "you diddnt type anything!"
            else:
                print " you diddnt type anything!"
        elif answerone == "no" or answerone == "n":
            break   
            print "well this was a fun game wasnt it?"
        else:
            print "you diddnt type anything!"

1 个答案:

答案 0 :(得分:2)

elif answerthree == "go to gas station":与任何if

不匹配