Python ';对于in';原始输入后停止工作

Python ';对于in';原始输入后停止工作,python,python-2.7,for-loop,if-statement,raw-input,Python,Python 2.7,For Loop,If Statement,Raw Input,我正在创建一个程序,英雄在10秒内拯救了两名人质。他需要做的第一件事是决定先救谁,然后键入炸弹代码来营救人质,如果用户键入的人质姓名错误,他可以再次键入。但是在我输入错误,循环停止后,或者在我保存第一个人质后,循环停止 代码如下: holly = True molly = True for i in range(0,11): print "Who will you save?" print "Time paste:", i decide = raw_input("&g

我正在创建一个程序,英雄在10秒内拯救了两名人质。他需要做的第一件事是决定先救谁,然后键入炸弹代码来营救人质,如果用户键入的人质姓名错误,他可以再次键入。但是在我输入错误,循环停止后,或者在我保存第一个人质后,循环停止

代码如下:

holly = True
molly = True

for i in range(0,11):
    print "Who will you save?"
    print "Time paste:", i

    decide = raw_input("> ")

    if decide == "Holly" and holly:
        print "You decided to save Holly."
        print "Whats the code?"
        code = random.randint(100,1000)
        print code
        decide = int(raw_input("> "))
        if decide != code:
            exit('You are dead!')
        print "You saved Holly!"
        holly = False
    elif decide == "Molly" and molly:
        print "You decided to save Molly."
        print "Whats the code?"
        code = random.randint(100,1000)
        print code
        decide = int(raw_input("> "))
        if decide != code:
            exit('You are dead!')
        print "You saved Molly!"
        molly = False
    elif not holly and not molly:
        print "You saved both of them!"
        break
    else:
        print "Try again!"
我在课堂上做这一切,下面是完整的代码:

class Mountains(object):
    def enter(self):
        print "After you defeated Josh. You headed towards the mountains."
        print "There you're final target sits."
        print "Jim the \"Knigh\""
        print "He has 2 hostages. Holly and Molly, you have 10 seconds to save them."
        print "They are bought straped to a bomb, each one in different location"
        print "Each bomb has a 3 digit code."

        holly = True
        molly = True

        for i in range(0,11):
            print "Who will you save?"
            print "Time remaining:", i

            decide = raw_input("> ")

            if decide == "Holly" and holly:
                print "You decided to save Holly."
                print "Whats the code?"
                code = random.randint(100,1000)
                print code
                decide = int(raw_input("> "))
                if decide != code:
                    exit('You are dead!')
                print "You saved Holly!"
                holly = False
            elif decide == "Molly" and molly:
                print "You decided to save Molly."
                print "Whats the code?"
                code = random.randint(100,1000)
                print code
                decide = int(raw_input("> "))
                if decide != code:
                    exit('You are dead!')
                print "You saved Molly!"
                molly = False
            elif not holly and not molly:
                print "You saved both of them!"
                break
            else:
                print "Try again!"

            if holly and molly:
                exit("You are dead!")

            print "After you saved both, Jim comes in angry!"
            print "He takes his shotgun! And startes firing!"
            print "You take cover, and start to think where to shoot!"
            print "You only have 4 bullets! Make it count!"

            hero = 100
            villain = 100
            bullets = 4
            direction = ["up", "down", "left", "right"]

            while True:
                print "In which direction do you shoot?"
                print "Hero health:",hero
                print "Villain health:",villain
                print "Bullets left:", bullets

                if hero < 0:
                    exit("You are dead.")
                elif villain < 0:
                    exit("You win")
                elif bullets == 0:
                    exit("You are dead.")

                bullets -= 1
                shoot = random.choice(direction)
                print shoot

                choice = raw_input("> ")

                if choice == shoot:
                    print "You shoot %s, hitting Jim but he also hits you." % shoot
                    hero -= random.randint(20,30)
                    villain -= random.randint(30,50)
                elif choice != shoot:
                    print "You shoot %s, but you missed. Jim didn't miss." % shoot
                    hero -= random.randint(10,20)
                else:
                    print "Try again."
        else:
            print "Try again"
类山(对象):
def输入(自我):
打印“在你打败Josh后,你向山上走去。”
打印“这是你的最终目标。”
打印“吉姆骑士”
打印“他有两名人质。霍莉和莫莉,你有10秒时间救他们。”
打印“他们被带到炸弹上,每个在不同的位置”
打印“每个炸弹有一个3位数的代码。”
霍莉=真的
莫莉=真的
对于范围(0,11)内的i:
打印“你将拯救谁?”
打印“剩余时间:”,i
决定=原始输入(“>”)
如果Decise==“Holly”和Holly:
打印“你决定救霍莉。”
打印“代码是什么?”
代码=random.randint(1001000)
打印代码
decise=int(原始输入(“>”)
如果决定!=代码:
退出(“你死了!”)
打印“你救了霍莉!”
霍莉=错
elif Decise==“Molly”和Molly:
打印“你决定救莫莉。”
打印“代码是什么?”
代码=random.randint(1001000)
打印代码
decise=int(原始输入(“>”)
如果决定!=代码:
退出(“你死了!”)
打印“你救了莫莉!”
莫莉=错
elif不是holly也不是molly:
打印“你两个都保存了!”
打破
其他:
打印“再试一次!”
如果霍莉和莫莉:
退出(“你死了!”)
打印“两个都保存后,吉姆生气了!”
打印“他拿着猎枪!开始射击!”
打印“你找掩护,开始考虑在哪里拍摄!”
打印“你只有4颗子弹!算了吧!”
英雄=100
恶棍=100
子弹数=4
方向=[“向上”、“向下”、“向左”、“向右”]
尽管如此:
打印“你朝哪个方向射击?”
打印“英雄健康:”,英雄
打印“恶棍健康:”,恶棍
打印“左项目符号:”,项目符号
如果英雄<0:
退出(“你死了。”)
elif恶棍<0:
退出(“你赢了”)
elif项目符号==0:
退出(“你死了。”)
子弹-=1
射击=随机。选择(方向)
照片
选择=原始输入(“>”)
如果选择==射击:
打印“你开枪打了%s,打了Jim,但他也打了你。”%shot
hero-=random.randint(20,30)
恶棍-=随机的随机数(30,50)
埃利夫选择!=拍摄:
打印“您拍摄了%s,但您错过了。吉姆没有错过。”%shot
hero-=random.randint(10,20)
其他:
打印“重试”
其他:
打印“重试”

我使用continue解决了这个问题。以下是我插入的部分,请继续:

if decide == "Holly" and holly:
    print "You decided to save Holly."
    print "Whats the code?"
    code = random.randint(100,1000)
    print code
    decide = int(raw_input("> "))
    if decide != code:
        exit('You are dead!')
    print "You saved Holly!"
    holly = False
    continue
elif decide == "Molly" and molly:
    print "You decided to save Molly."
    print "Whats the code?"
    code = random.randint(100,1000)
    print code
    decide = int(raw_input("> "))
    if decide != code:
        exit('You are dead!')
    print "You saved Molly!"
    molly = False
    continue
else:
    print "Try again!"
    continue

我无法重现这个问题。代码完全按照它看起来的方式运行。代码单独运行时效果良好。但是在一个类中它不是。你如何在类中使用代码?请给出你的答案并展示那部分。