Python while循环-猜年龄-无次数限制

#python 2.7版本下测试

#while循环 if判断 简单介绍

#猜年龄的游戏 -无次数限制   
age_of_tom = 55
while True:
    age = int(input("Guess the age:"))  #python3.x版本中input替代了raw_input()
    if age == age_of_tom:
        print("Yes, You are right!")
        break
    elif age > age_of_tom:
        print("No, Try a smaller value!")
    else:
        print("No, Try a bigger value!")    
#while循环结尾要保留空格

你可能感兴趣的:(Python while循环-猜年龄-无次数限制)