I am working on "Learn Python the hard way" and have a little understanding question regarding while loops and boolean operators.
def bear_room():
print "There is a bear here."
print "The bear has a bunch of honey."
print "The fat bear is in front of another door."
print "How are you going to move the bear?"
bear_moved = False
while True:
choice = raw_input("> ")
if choice == "take honey":
dead("The bear looks at you then slaps your face off.")
elif choice == "taunt bear" and not bear_moved:
print "The bear has moved from the door. You can go through it now."
bear_moved = True
elif choice == "taunt bear" and bear_moved:
dead("The bear gets pissed off and chews your leg off.")
elif choice == "open door" and bear_moved:
gold_room()
else:
print "I got no idea what that means."
The script moves to next "step" as soon as I type in "taunt bear". Then I can type in "open door" and I go on to the next function.
But, should a while loop not run endless until something is false
? What happens after the "taunt bear" is that bear_moved
is set to True
. How can it go on the next step then. Furthermore, I do not understand the and not bear_moved
statement. Shouldnt that set bear_moved
to false? But it is already set to false
. It confuses me.
Thanks for any explanation.