dimanche 19 mars 2017

Python: Using random.choice with if/elif/else statement

I'm attempting to use a random choice statement in python, with an if/elif/else statement which would continue the program. The random.choice bit works fine in the program, as it selects a random encounter, however it then chooses quite random options on the if/elif/else option. If the random.choice selects 'a giant monster' I want it to say '..you are eaten alive' and vice versa. At the moment, only the squawk and you slowly approach options seem to work, but don't necessarily correlate with the choice of monster. This is my code:

 print("THUMP THUMP THUMP")
    print("..you turn around and you see..")
    monster = ("a giant monster", "a giant eagle", "a dog")
    print(random.choice(monster))
    monster1 = (random.choice(monster))
    time.sleep(1)
    if monster1 == "a giant monster":
        print(".. you are eaten alive :(")
    elif monster1 == "a giant eagle":
        print("*SQUAWK*")
    else:
        print("you slowly approach")

Thanks.




Aucun commentaire:

Enregistrer un commentaire