您的位置:首页 > 编程语言 > Python开发

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

2018-04-03 16:27 363 查看
#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循环结尾要保留空格
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: