vendredi 26 mai 2017

For in Python stops working after raw_input

I am creating a program where the hero saves two hostages in 10 seconds. The first things he needs to do is decide who to save first, then type the code for bomb to rescue the hostage, if the user types the name of the hostage wrong he can type it again. But after I type wrong once the loops stops or after i finnished saving the first hostage the loop stops.

This is the code:

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!"

Aucun commentaire:

Enregistrer un commentaire