猜测年龄:
#尝试三次后询问是否继续?
age_of_tao=27
count=0
while count < 3:
guess_age=int(input("guess_age:"))
if age_of_tao == guess_age:
print ("right!")
break
elif age_of_tao>guess_age:
print ("think smaller!")
else:
print("think big!")
count +=1
if count == 3:
continue_confirm = input("Do you want to play again?")
if continue_confirm == ‘y‘:
count =0
#尝试三次结束
age_of_tao=27
count=0
while count < 3: #[count=0 while count <3 ... count +=1 ] = [for i in range (3)]
guess_age=int(input("guess_age:"))
if age_of_tao==guess_age:
print ("right!")
break
elif age_of_tao>guess_age:
print ("think smaller!")
else:
print("think big!")
count +=1
else: # [else] = [if count==3]
print ("you have tried too many times")
原文:https://www.cnblogs.com/taosun/p/11746096.html