python while 循环-猜年龄-有次数限制

#python 2.7测试

#guess-猜年龄的游戏 -有次数限制

times = 1        
age_of_tom = 55
print("You have 5 times to guess " )
while times < 6:
    age = int(input("Guess the age:"))  #python的输入全部为字符,需要类型转换
    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!")    
    times = times + 1    
else:
    print("You have tried too many times")        
#while循环结尾要保留空格

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