Python编程:从入门到实践 > 前言中的猜数字小游戏:
while True:
age=int(input("I'm thinking of a number! Try to guess the number I'm thinking of :"))
age_guess=int(input())
while age_guess!=age:
if age_guess<age:
age_guess=int(input('Too low! Guess again:'))
else:
age_guess=int(input('Too high! Guess again:'))
if age_guess==age:
answer=input("That's it! Would you like to play again? (yes/no)")
if answer=="no":
print("Thanks for playing!")
break