python 笔记 之 while 循环

# while 循环
# while 条件判断:
#       逻辑操作

a = 10
while a >= 1:
    print(a)
    a -= 1

score = 59
while True:
    if score > 60:
        print("恭喜你及格了")
    else:
        print("菜逼,等着补考吧!")
# python 的死循环不会吧 cpu 运行到100%  python本身会有控制

 

# while True:  ====  while 1:
#  需要把True转换为1     执行效率高
#   计算机的底层是 0 1  所以最终表现True-->1


number = 100
while 1:
    if number <60:
        print("不及格")
    elif number ==60:
        print("正好及格")
    else:
        print("及格")

 

#死循环的例子,直到输入正确
while 1:
    age = raw_input("Please input your age:")
    if age.strip():
        if age.strip().isdigit():  #isdigit 判断是数字,是数字返回true
            if int(age)>=18:
                print("你是一个成年人")
            else:
                print("你还是一个小屁孩!")
            break
        else:
            print("你输入的不是数字,请重新输入:")
            continue
    else:
        print("你输入的只有空格,请重新输入:")
        continue

转载于:https://my.oschina.net/u/3824134/blog/1793499

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值