码迷,mamicode.com
首页 > 其他好文 > 详细

用while循环写猜年龄以及优化版

时间:2018-07-04 22:49:25      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:...   print   you   else   time   inpu   bigger   循环   int   

增加:1、循环猜,2、最多猜3次,3、超过3次输出猜次数过多:

 

age_of_XueKe=18

count=0
while True:
if count==3:
break
age = int(input("age:"))
if age == age_of_XueKe:
print("Yes,you got it!")
break
elif age >age_of_XueKe:
print("Think smaller!")
else:
print("Think bigger!")
count=count+1
if count==3:
print("You have tried too many times...")

优化版:

age_of_XueKe=18

count=0
while count<3:
age = int(input("age:"))
if age == age_of_XueKe:
print("Yes,you got it!")
break
elif age >age_of_XueKe:
print("Think smaller!")
else:
print("Think bigger!")
count=count+1
else:
print("You have tried too many times...")

用while循环写猜年龄以及优化版

标签:...   print   you   else   time   inpu   bigger   循环   int   

原文地址:https://www.cnblogs.com/shmilymima/p/9265542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!