• Day 1 入门知识及作业


    python特征

    python2 与 python3 区别

    2的源码不标准, 重复代码多

    3同意, 标准, 去重

    ---------------

    编译型: 一次性执行所有程序编译成二进制文件, 开发效率低, 运行速度快, 不能跨平台.

    解释型: 一行一行执行, 开发效率高, 可以快平台, 运行速度较慢.

    a = '''

    多行注释

    可以赋值

    给变量

      '''

    while  else

    当while被 break 打断, 不执行else

     

    练习题 Day 1

    1、使用while循环输入 1 2 3 4 5 6     8 9 10

    num = 0
    while num <= 9:
        num += 1
        if num > 6 and num < 8:
            continue
        print(num)
    View Code
    2、求1-100的所有数的和
    num = 1
    sum = 0
    
    while num < 101:
        sum += num
        num += 1
    
    print(sum)
    View Code

    3、输出 1-100 内的所有奇数

    odd = 0
    
    while odd < 100:
        odd += 1
        if odd % 2 ==1:
            print(odd)
    View Code
     1 a = 0
     2 
     3 while a < 100:
     4     a += 1
     5     if a % 2:
     6         print(a)
     7         
     8 -------------
     9 
    10 a = 1
    11 
    12 while a < 101:
    13     print(a)
    14     a += 2
    View Code

     4、输出 1-100 内的所有偶数

    odd = tuple(range(1,100))
    
    for i in odd:
        if i % 2 == 1:
            print(i)
    View Code

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

     1 odd = tuple(range(1,1000))
     2 sum = 0
     3 
     4 for i in odd:
     5     if i % 2 != 0:
     6         sum -= i
     7     else:
     8         sum += i
     9 
    10 
    11 print(sum)
    View Code

    View Code

    6、用户登陆(三次机会重试)

    error = 0
    left = 3 - error
    
    NAME = 'XIONG'
    PASSWORD = 'qq112233'
    
    while left > 0:
        name = input("Please input your sign in name: ")
        password = input("Please input your password: ")
        if name == NAME and password == PASSWORD:
            print("YOUR NAME IS: " + name)
            print("YOUR PASSWORD IS: " + password)
            print('Congratulations,you are correct')
            break
        else:
            error += 1
            if error == 3:
                print('Sorry, too many times error')
                break
            print("YOUR NAME IS: " + name)
            print("YOUR PASSWORD IS: " + password)
            print('Sorry, you are wrong. Please try again')
            print(str(left - error) + 'time(s) left')
    View Code
  • 相关阅读:
    工作中Linux常用命令
    自动化测试
    Firefox/Chrome WebDriver浏览器驱动
    Appium
    Python+selenium进行浏览器的连接ChromeOptions
    文件及异常捕获处理
    面向对象练习题
    python函数&面向对象
    python基础
    python8道练习题
  • 原文地址:https://www.cnblogs.com/comeonsean/p/9859927.html
Copyright © 2020-2023  润新知