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("三次机会已用完,退出猜测")
    
  • 相关阅读:
    如何使用 IDEA 向 Github 上推送和拉取代码
    CST时间和GMT时间注意事项
    CST时间GMT时间转换
    MultipartFile转InputStream
    Java中InputStream和String之间的转化
    Fastjson 之 Json 对象、Json 字符串、Java 对象之间的转换
    Git 撤销修改
    Springboot 配置文件之 Yaml
    IDEA 快速搭建一个 Springboot 应用
    ZooKeeper 安装
  • 原文地址:https://www.cnblogs.com/zuiyouyingde/p/12452006.html
Copyright © 2011-2022 走看看