zoukankan      html  css  js  c++  java
  • 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
    
    
     
  • 相关阅读:
    数组中重复的数字
    第一个只出现一次的字符位置
    丑数
    字符串的排列
    把数组排成最小的数
    圆圈中最后剩下的数
    同步通信与异步通信
    S3C2440 UART串口驱动
    ARM处理器工作模式
    s3c2440系统时钟
  • 原文地址:https://www.cnblogs.com/zhanghaoyang/p/10240684.html
Copyright © 2011-2022 走看看