Hard Way Упражнение 35 Мне интересно, как линииLearn Python логическое выражение
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.")
... реализовать переменную bear_moved
? Он уже определен как False
перед циклом while
, и мне интересно, почему его сравнивают с тем, что введено в «выборе» и как он проверяет его, когда вы просто набираете свой ответ. Кроме того, если он говорит «not
» 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."
Я действительно начинаю ненавидеть эту книгу, и особенно это упражнение. Связанный список показывает, сколько людей не понимает этот код, потому что книга не объяснила это должным образом. И эта строка 'gold_room()' (обратите внимание, что там нет 'return' там ...) приводит к сотням людей, упорядочивающих функции таким образом, и с общими проблемами различных проблем, которые вызывают ... – abarnert