我真的沒有得到什麼功能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