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("三次机会已用完,退出猜测")
    
  • 相关阅读:
    牛客练习赛64 C 序列卷积之和 (推式子 数学)
    HDU 汉诺塔系列
    牛客挑战赛40 A-小V和方程 (思维、数学、整数拆分、dp)
    HDU 2048 2049 (错位排列)
    组合数奇偶性判断
    bzoj 1249: SGU277 HERO
    CF70D Professor's task
    P3829 [SHOI2012]信用卡凸包
    CF316E3 Summer Homework
    P5284 [十二省联考2019]字符串问题
  • 原文地址:https://www.cnblogs.com/zuiyouyingde/p/12452006.html
Copyright © 2011-2022 走看看