我真的没有得到什么功能bear_moved
是?为什么需要“bear_moved”?
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."
这是学习Python坚硬方式,锻炼35
请注意,我强烈建议你找一本不同的书,因为现在LPTHW已经过时了(现在Python 2已经成为一种传统语言了)。 –
bear_moved不是函数,它是一个指示熊是否已移动的变量。 当你嘲讽这只熊时,这个变量被设置为True,然后你可以打开门。 – sobek
这看起来像一个非常腥的程序流程,因为没有任何可能的方式来打破这个循环,并且最终会越过兔子洞。你不明白布尔的什么部分? – Sayse