1、死循环学会用法
a = 1
while True:
print(a)
a +=1
2、无限次输入,直到输对,才退出
_age = 18
while True:
guess_age = int(input("guess_age:"))
if guess_age == _age:
print("Good!!!!")
break
else:
print("no,please input")
3、限制输入三次,超过三次,提示输入次数太多退出
_age = 18
count = 0
while 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 +=1
else:
print("you have tried too many times...quit")
原文地址:http://blog.51cto.com/limingyu/2097350
时间: 2024-10-17 16:34:07