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("三次机会已用完,退出猜测")
    
  • 相关阅读:
    Saltstack module apache 详解
    Saltstack module ip 详解
    Saltstack module iosconfig 详解
    Saltstack module introspect 详解
    Saltstack module inspector 详解
    Saltstack module ini 详解
    Saltstack module incron 详解
    Modbus 指令 RS485指令规则
    停车系统对接第三方在线支付平台(二)
    停车系统对接第三方在线支付平台
  • 原文地址:https://www.cnblogs.com/zuiyouyingde/p/12452006.html
Copyright © 2011-2022 走看看