# 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