lundi 27 juillet 2015

My elif/else statements in Python are not working

I am learning python right now, and this is the code I have so far, just as a little excercise with conditionals and such:

def the_flying_circus():
    animals = raw_input("You are the manager of the flying circus. Which animals do you select to perform today?")
    if animals == "Monkeys":
        num_monkeys = raw_input("How many monkeys are there?")
        if num_monkeys >= 20:
            return "Don't let all of 'em hurt you!"
        elif num_monkeys < 20 and num_monkeys >= 5:
            return "Not too many, but be careful!"
        elif num_monkeys < 5:
            return "You're in luck! No monkeys to bother you."
    elif animals == "Anteaters":
        return "What the hell kinda circus do you go to?!"
    elif animals == "Lions":
        height_lion = raw_input("How tall is the lion (in inches)?")
        if height_lion >= 100:
            return "Get the hell outta there."
        elif height_lion < 100:
            return "Meh. The audience usually has insurance."
    else:
        return "Dude, we're a circus, not the Amazon rainforest. We can only have so many animals."
print the_flying_circus()

So the problem I'm having is that the code works fine, until after I've entered an animal. If I do anteaters, it's fine. But if I do monkeys or lions, no matter what number I put in, only the string under the initial if statement is printed ("Don't let all of em hurt you" or "get the hell outta there"). I'm also not getting any errors. Why is this?

Aucun commentaire:

Enregistrer un commentaire