1、死循环学会用法
a = 1while True: print(a) a +=1
2、无限次输入,直到输对,才退出
_age = 18while True: guess_age = int(input("guess_age:")) if guess_age == _age: print("Good!!!!") break else: print("no,please input")
3、限制输入三次,超过三次,提示输入次数太多退出
_age = 18count = 0while count<3: guess_age = int(input("guess_age:")) if guess_age == _age: print("Good!!!!") break elif guess_age > _age: print("no,cai da le ...") else: print("no,cai xiao le ...") count +=1else: print("you have tried too many times...quit")