samedi 5 novembre 2016

Python If/Else Only Returning In Order, Not By Logic

When an integer containing "0" or "4" is entered, this if-statement only returns the first in the statement.

For example, in the code below, if I enter "60", it will execute:

print "Nice, you're not greedy - you win!" exit(0)

NOT

dead("You greedy bastard!")

as I expected with how_much >= 50.

Have tried a bunch of changes, but can't seem to get to to execute as intended. Anyone know what's going on here?

def gold_room():
    print "This room is full of gold. How much do you take?"
    number_type = False

    while True:

        choice = raw_input("> ")

        how_much = int(choice)

        if "0" in choice or "4" in choice and how_much < 50:
            print "Nice, you're not greedy - you win!"
            exit(0)
        elif "0" in choice or "4" in choice and how_much >= 50:
            dead("You greedy bastard!")
        else:
            print "Man, learn to type a number. Put a 0 or a 4 in your number."

Aucun commentaire:

Enregistrer un commentaire