So I am an absolute beginner and working through Zed Shaw's Learn Python The Hard Way. For some reason today when I am running a program I am getting different outputs randomly. Below is a a portion of my code as well as some of the inconsistent input/output. I have tried this multiple times in a row and sometimes it the code works properly and calls the next function and sometimes it skips over the majority of it.
Here is my code that isn't running consistently ...
def bear_room():
print "There is a bear in 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:
next = raw_input(">")
if next == "take honey":
dead("The bear looks at you and slaps your face off.")
elif next == "taunt bear" and not bear_moved:
print "The bear has moved from the door. You can go through it now."
bear_moved = True
elif next == "taunt bear" and bear_moved:
dead("The bear gets pissed off and chews your leg off.")
elif next == "open door" and bear_moved:
gold_room()
else:
print " I have no idea what that means."
Here is some of the inconsistent output... Here I run the program and use the input "left" at the prompt.
Theresa-Beckers-MacBook-Pro:Summer 2013 Python leafgirl12$ python ex35.py
You are in a dark room.
There is a door to your right and left
Which one do you take?
>left
You stumble around the room until you starve. Good job!
Here I do the same thing immediately after and this time it runs through but the output is different.
Theresa-Beckers-MacBook-Pro:Summer 2013 Python leafgirl12$ python ex35.py
You are in a dark room.
There is a door to your right and left
Which one do you take?
>left
There is a bear in here.
The bear has a bunch of honey.
The fat bear is in front of another door.
How are you going to move the bear?
I know in C++ when creating new variables it can be a matter of stack vs heap, but I con't find any answers for Python functions on the same computer. I have also retyped my code in case there is some indentation error that I am not seeing. A few times I have been able to get the correct output when I continue and type "take honey" but this only works half the time and "taunt bear" has yet to work at all. It just passes straight through to the else. Any thoughts? Does this makes sense?
bear_roomcode that isn't running consistently; it's thestartcode that isn't running consistently.print 'You said "{!r}"'.format(next)after eachraw_input()statement, so you can see exactly what you typed.SyntaxErrors andIndentationErrors—or, worse, code that runs, but with crazy control flow that makes no sense. The best thing to do is to always use spaces. Almost any editor smarter than Notepad can be configured to turn the tab key into spaces automatically, so do that.x = 3is sort of likeauto x = shared_ptr<int>(new int(3));. (But only sort of… that3literal was itself a reference to a heap object, andxprobably ends up as another reference to the same object.)