我在練習35中的一些問題是「學習python的難辦法」。學習python的困難之路,練習35
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:
next = raw_input("> ")
if next == "take honey":
dead("The bear looks at you then 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 got no idea what that means."
a)我不明白爲什麼While激活。在第6行中,我們寫出bear_moved條件爲False。所以如果它是假的,並且當它是真時激活,它不應該激活!
b)IF和ELIF行中的AND運算符也有問題。我們爲什麼問如果bear_moved值的變化?除了第33行以外,塊中沒有其他指令會影響bear_moved(但該行退出while)。
我不確定我是否已經解釋了我自己,請告訴我,如果我沒有。並感謝你的答案,我是一個完整的新手。
http://learnpythonthehardway.org/book/ex35.html