因此,我是一个绝对的初学者,并通过Zed Shaw的《艰难的学习Python》来学习。 由于某些原因,今天当我运行一个程序时,我随机得到不同的输出。下面是我的一部分代码以及一些不一致的输入/输出。我已经连续多次尝试这种方法,有时代码可以正常工作并调用下一个函数,有时它会跳过大部分函数。在
下面是我的代码,它运行不一致。。。在
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."
以下是一些不一致的输出。。。 在这里,我运行程序并在提示符处使用输入“left”。在
^{pr2}$在这里,我马上做同样的事情,这次它运行,但输出是不同的。在
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?
我知道在C++中创建新变量时,它可能是堆栈和堆的问题,但是在同一台计算机上找不到任何Python函数的答案。我还重新输入了我的代码,以防有一些缩进错误,我没有看到。有几次,当我继续输入“take honey”时,我能得到正确的输出,但这只起了一半的作用,“嘲讽熊”还没有起作用。它只是直接穿过另一个。
有什么想法吗?这有道理吗?在
从the code for this exercise来看,您一定是在其中一次尝试中拼错了“left”,请注意,这可能是一些不必要的大写字母或开头或结尾处的意外空格。在
以下是相关代码:
如果您准确地键入“left”并按enter键,则应始终输入bear room。在
在“left”或“right”后面加上空格会饿死你。:)
相关问题 更多 >
编程相关推荐