循环进阶-猜年龄

项目1:允许用户最多猜三次,中间猜对了,直接跳出循环。

age = 56
count = 0

while count <= 2:
    count = count + 1
    input_number = input("please input your age")
    if int(input_number) != age:
        print("You are so stupid")
    if int(input_number) == age:
        print("You are so clever\nThe age is 56")
        break
View Code

项目2:允许用户猜三次,中间猜对了,直接跳出循环,没有猜对询问用户是否还想玩,想玩继续猜。

age = 44
count = 0
P = "Y"
while count <= 3:
    input_number = input("please input your age:")
    count +=1
    if int(input_number) == age:
        print("You are so clever,the age is right.")
        break
    elif (count == 3) and int(input_number) != age:
        choice = input("The time is enough,please input your choice Y?orN")
        if choice ==P:
            count = 0
            print("You are so obstinate")
        else:
            pass
View Code

 

posted @ 2019-03-03 16:53  上古战神  阅读(338)  评论(0编辑  收藏  举报