加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

day05

发布时间:2020-12-20 10:45:11 所属栏目:Python 来源:网络整理
导读:目录 输入姑娘的年龄后,进行以下判断: 如果姑娘小于18岁,打

目录

  1. 输入姑娘的年龄后,进行以下判断:

    1. 如果姑娘小于18岁,打印“不接受未成年”
    2. 如果姑娘大于18岁小于25岁,打印“心动表白”
    3. 如果姑娘大于25岁小于45岁,打印“阿姨好”
    4. 如果姑娘大于45岁,打印“奶奶好”
    age_inp = input("请输入你的年龄")
    age_inp_int = int(age_inp)
    if age_inp_int < 18:
        print("不接受未成年")
    elif age_inp_int > 18 and age_inp_int < 25:
        print("心动表白")
    elif age_inp_int > 25 and age_inp_int < 45:
        print("阿姨好")
    else:
        print("奶奶好")
  2. 预习while循环,打印1-100之间的奇数和

    count = 1
    total = 0
    while count <=100:
        if count % 2 == 1:
            total += count
        count += 1
    print(total)
  3. 预习while循环,猜年龄游戏升级版,有以下三点要求:

    1. 允许用户最多尝试3次
    2. 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序
    3. 如果猜对了,就直接退出
    count = 1
    while True:
        age = input("请输入你的年纪")
        age = int(age)
        if age == 21:
            print("你猜对了")
            break
        print("猜错了")
        if count == 3:
            play = input("是否还想继续玩? Y/y/N/n:")
            if play == "Y/y":
                count = 1
                continue
            elif play == "N/n":
                break
            else:
                print("输入有误")
                break
        count = count + 1
    
    count = 1
    while count <= 3:
        x = input("请输入")
        timer = 3 - count
        total = "用户名或密码输入错误,剩余%s次机会" %(timer)
        print(total)
        count +=1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读