python_1

猜测年龄:

#尝试三次后询问是否继续?
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")


posted @ 2019-10-26 22:39  sun_tao  阅读(72)  评论(0)    收藏  举报