用while循环写猜年龄以及优化版
Posted shmilymima
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用while循环写猜年龄以及优化版相关的知识,希望对你有一定的参考价值。
增加: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循环写猜年龄以及优化版的主要内容,如果未能解决你的问题,请参考以下文章