首页 > 其他 > 详细

跟随Alex学习循环进阶-猜年龄(纯属爱好,自己看自己的代码都想吐...(⊙﹏⊙))

时间:2019-03-03 17:09:17      阅读:150      评论:0      收藏:0      [点我收藏+]

项目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

 

跟随Alex学习循环进阶-猜年龄(纯属爱好,自己看自己的代码都想吐...(⊙﹏⊙))

原文:https://www.cnblogs.com/jb9527/p/10466329.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!