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循环不是太熟悉可以模仿上边的代码使用。

相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值