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."
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.
这是为了表明我对布尔值的理解。在测试行next == "taunt bear" and not bear_moved
中,如果我的输入是taunt bear
,结果是True and True
,这将继续循环。
所以让我感到困惑的是线路测试next == "taunt bear" and bear_moved
。如果我的输入是taunt bear
,它应该是"taunt bear" == "taunt bear"
,bear_moved
哪个是True and True
?这意味着循环将继续而不是取消它。