• python基础循环


    1、使用while循环输入1234568910
     n = 1
     while n < 11:
         if n == 7:
             pass
         else:
             print(n)
         n = n + 1
    
    
    2、求1 - 100的所有数的和
    
    
    n = 1
    s = 0
    while n < 101:
        s = s + n
        n = n + 1
    
    print(s)
    
    
    3、输出1 - 100内的所有奇数

    n = 1
    while n < 101:
        temp = n % 2
        if temp == 0:
            pass
        else:
            print(n)
        n = n + 1
    
    print('----end----')
    
    
    4、输出1 - 100内的所有偶数

    n = 1
    while n < 101:
        temp = n % 2
        if temp == 0:
            print(n)
        else:
            pass
        n = n + 1
    
    print('----end----')

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

    n = 1
    s = 0  # s是之前所有数的总和
    while n < 100:
        temp = n % 2
        if temp == 0:
            s = s - n
        else:
            s = s + n
        n = n + 1
    
    print(s)
    6、设计登录小程序,有三次机会

    import datetime
    username = "keys"
    password = "123456"
    no = 2
    while no >= 0:
        input_name = input("请输入你的账号:")
        input_pswd = input("请输入你的密码:")
        if username == input_name and password == input_pswd:
            print("恭喜您"+username+"登录成功,今天是{}".format(datetime.datetime.today()))
            break
        elif input_name == "" or input_pswd == "":
            print("用户名或密码不能为空,请重新输入")
            print("您还有"+str(no)+"次机会!!!")
        else:
            if username != input_pswd or password != input_pswd:
                print("
    账号或密码错误,请重新输入")
                print("温馨提示,您还有"+str(no)+"次机会")
            else:
                print("您的次数已用完。")
        no = no -1
    
    
     
  • 相关阅读:
    .net core 大文件分片上传
    Python 运算符
    CF1398G Running Competition FFT
    Luogu「StOI-2」简单的树 树链剖分+线段树+倍增
    LOJ#3145. 「APIO2019」桥梁 分块+可撤销并查集
    【UNR #4】序列妙妙值 分块+DP
    LuoguP5008 [yLOI2018] 锦鲤抄 tarjan+贪心
    windows提权
    基于 Laravel 框架的内容管理系统
    趣谈、浅析CRLF和LF
  • 原文地址:https://www.cnblogs.com/zhanghaoyang/p/10240684.html
Copyright © 2020-2023  润新知