while循环的用法

while 循环的用法(循环前加入停止条件)

def dead(why):
    print why, "\nGood job!\n"
    exit(0)

bear_moved = False

while True:
    next = raw_input("> ")

    if next == "take honey":
        dead("The bear looks at you then slaps your face off.\n")
    elif next == "taunt bear" and not bear_moved:
        print "The bear has moved from the door. You can go through it now.\n"
        bear_moved = True
    elif next == "taunt bear" and  bear_moved:
        dead("The bear gets pissed off and chews your leg off.\n")
    elif next == "open door" and bear_moved:
        pass
    else:
        print "I got no idea what that means.\n"

如果对while循环不是太熟悉可以模仿上边的代码使用。

你可能感兴趣的:(python笔记)