python猜年龄

mac2022-06-30  71

#若输入年龄正确,完成循环,最多只能输入三次,停止本次循环(使用while循环)age = 28count = 0while count<3: _age = int(input("age:")) if _age==age: print("you got it!") break elif _age>age: print("think smaller") else: print("think bigger") count +=1else: print("you tried many times") #若输入年龄正确,完成循环,最多只能输入三次,停止本次循环(使用for循环) age = 28for i in range(3): _age = int(input("age:")) if _age==age: print("you got it!") break elif _age>age: print("think smaller") else: print("think bigger")else: print("you tried many times")

转载于:https://www.cnblogs.com/mahaigang/p/9848976.html

相关资源:python--猜年龄
最新回复(0)