while/for循环+if猜年龄

Posted 子夜星云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了while/for循环+if猜年龄相关的知识,希望对你有一定的参考价值。

_oldboy_age = 56
count = 0
while count <3:
guess_age = int(input("guess_age:"))
if guess_age == _oldboy_age:
print("yes ,you right!")
break
elif guess_age > _oldboy_age:
print("think smaller")
else:
print("think bigger")

count +=1
if count == 3:
confirm = input("Do want to keep guessing?")
if confirm != ‘n‘:
count = 0


else:

print("you have try too much times,get off!")



--------------------------------------------------------------
_oldboy_age = 56

for a in range(3):
guess_age = int(input("guess_age:"))
if guess_age == _oldboy_age:
print("yes ,you right!")
break
elif guess_age > _oldboy_age:
print("think smaller")
else:
print("think bigger")




else:

print("you have try too much times,get off!")

以上是关于while/for循环+if猜年龄的主要内容,如果未能解决你的问题,请参考以下文章

Day1:循环语句(While,For)

流程控制(if while for)

if,while,for循环

猜年龄---for循环

循环和控制语句

4 常见循环if,while,for