python while循环-猜年龄-多次后提问是否继续

#guess-猜年龄的游戏 -有次数限制,到3此后提示是否继续   


times = 1        
age_of_tom = 55
print("You have 3 times to guess " )
while times < 4:
    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    
    if times == 4:
        cont = raw_input("Do you want to continue?,Y/N")  #python3中输入为input()
        if cont == 'Y':    times = 1
        else:   print("Bye")

你可能感兴趣的:(python while循环-猜年龄-多次后提问是否继续)