好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

day05

目录

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

如果姑娘小于18岁,打印“不接受未成年” 如果姑娘大于18岁小于25岁,打印“心动表白” 如果姑娘大于25岁小于45岁,打印“阿姨好” 如果姑娘大于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("奶奶好")

预习while循环,打印1-100之间的奇数和

count = 1
total = 0
while count <=100:
    if count % 2 == 1:
        total += count
    count += 1
print(total)

预习while循环,猜年龄游戏升级版,有以下三点要求:

允许用户最多尝试3次 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序 如果猜对了,就直接退出
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

查看更多关于day05的详细内容...

  阅读:16次