zoukankan      html  css  js  c++  java
  • 作业03

    作业(必做题):

    1. 使用while循环输出1 2 3 4 5 6 8 9 10

    count=0
    while count < 11:
        if count == 7:
            count+=1
            continue
        print(count)
        count+=1
    

    2. 求1-100的所有数的和

    count=0
    count1=count
    while count < 100:
        count+=1
        count1+=count
    else:
        print(count1)
    

    3. 输出 1-100 内的所有奇数

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

    4. 输出 1-100 内的所有偶数

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

    5. 求1-2+3-4+5 ... 99的所有数的和

    count=0
    count1=count
    while count < 100:
        count+=1
        if count%2!=0:
            count1+=count
        if count%2==0:
            count1-=count
    else:
        print(count1)
    

    6. 用户登陆(三次机会重试)

    username="qwert"
    userpsd="123"
    count=0
    while count<3:
        count+=1
        inp_name=input("请输入您的账号:")
        inp_psd=input("请输入您的密码:")
        if inp_name==username and inp_psd==userpsd:
            print("登录成功")
            break
        else:
            print("登录失败")
    else:
        print("您今日已输错3次,请明日再试")
    

    7:猜年龄游戏

    要求:

    允许用户最多尝试3次,3次都没猜对的话,就直接退出,如果猜对了,打印恭喜信息并退出

    d={"name":"qwert","age":"18"}
    count=0
    while count<3:
        count+=1
        inp_age=input("请输入qwert的年龄:")
        if inp_age==d["age"]:
            print("恭喜您,猜对了")
            break
        else:
            print("很遗憾,您已猜{x}次,共三次机会".format(x=count))
    else:
        print("三次机会已用完,退出猜测")
    
  • 相关阅读:
    32-Ubuntu-用户权限-03-修改文件权限
    31-Ubuntu-用户权限-02-ls输出信息介绍
    hdu2084 数塔
    hdu 1058 humble number
    HDU_2050 折线分割平面
    HDU_1030 Delta-wave 常数时间
    HDU_1021 Fibonacci Again 一些推论
    Gated Recurrent Unit(GRU)
    循环神经网络模型
    Bellman-Ford algorithm
  • 原文地址:https://www.cnblogs.com/zuiyouyingde/p/12452006.html
Copyright © 2011-2022 走看看