age_of_boy = 56 #设定的年龄是56,猜中了就是56岁
count = 0
while count < 3:
guess_age = int(input("guess age:"))
if guess_age == age_of_boy : #猜中的回馈
print("yes,you got it!")
break
elif guess_age > age_of_boy: #猜的数字大于设定年龄的反馈
print("think smaller...")
else:
print("think biger...") #猜的数字小于设定年龄的反馈
count +=1
if count == 3: #3次后,是否继续猜
countine_confirm = input("Do you want to keep guessing...? ")
if countine_confirm !='n':
count =0
else:
print("you have tried too many time ...fuck off !")
for循环的小例子
age_of_boy = 56
for i in range(3): #循环3次
guess_age = int(input("guess age:"))
if guess_age == age_of_boy :
print("yes,you got it!")
break
elif guess_age > age_of_boy:
print("think smaller...")
else:
print("think biger...")
else:
print("you have tried too many time ...fuck off !")