day02_ million annual salary into the second day of

day02

while-- keyword (infinite loop)

  • Format: while condition:

    Loop

    print(1)
    while True:
        print("痒")
        print("鸡你太美")
        print("卡路里")
        print("好运来")
        print("小三")
        print("小白脸")
        print("趁早")
        print("过火")
    print(2)
    
    falg = True
    while falg:
      print(1)
    print(2)
    
    
    # 正序的示范
    count = 1
    while count <= 5:
        print(count)
        count = count + 1
    
    # 倒序的示范
    count = 5
    while count:
        print(count)
        count = count - 1
    
    # 正序打印  25 - 57
    count = 25
    while count < 58:
        print(count)
        count = count + 1
    
    
    # 倒序打印  57 - 25
    count = 57
    while count > 24:
        print(count)
        count = count - 1
  • Digital is non-zero is zero False True

    # print(bool(0))
    # 数字中非零的都是True
  • break: terminate the loop, break the following code will not be executed

    while True:
        print(123)
        print(234)
        break   # 终止当前循环,break下方的代码不会进行执行
        print(345)
    print(1111)
  • continue: the end of the cycle, a direct jump to the next cycle (the last line of the loop body disguised), the following code will not be executed

    while True:
        print(123)
        print(234)
        print(345)
    
    while True:
        print(123)
        print(234)
        continue
        #continue 伪装成循环体中的最后一行代码(跳出当前循环继续下次循环)
        #continue 下面的代码不会执行
        print(345)
    print(1111)
  • while else: an overall (cycle), when the condition is satisfied when not performed, when the execution condition is not satisfied

    while True:
        print(111)
        break
    else:
        print(222)
    
    while True:
        print(111)
        break
    print(222)
    
    # while   else
    # 0.退出
    # 1.开始登录
    # 如果用户选择序号0就提示用户退出成功
    # 如果用户选择序号1就让用户输入用户名和密码然后进行判断,正确就终止循环,错误就重新输入
    srr = """
    0.退出
    1.开始登录
    """
    print(srr)
    num = int(input("请输入你要的数字:"))
    while num == 1:
        name_input = input("请输入你的用户名:")
        password_input = input("请输入你的密码:")
        name = "alex"
        password = "123"
        if name_input == name and password_input:
            print("登录成功")
            break
        else:
            print("用户名或者密码错误,请重新输入!")
    else:
        print("退出成功")
  • to sum up:

    • Break the cycle way:
      1. Make changes to conditions
      2. break
  1. break - break the current cycle (terminate the current cycle)

    1. continue - out of the current cycle continues for the next cycle (the last line of code disguised continue loop body)
    2. break and continue in common: they do not execute the following code

String formatting

a = "------------- info -------------"
b = "name:"
c = "age:"
d = "job:"
e = "-------------- end -------------"
name = input("name")
age = input("age")
job = input("job")
print(a + "\n" + b + name + "\n" + c + age + "\n"+ d + job + "\n" +e)
  • % Is a placeholder

  • %% (escape) escape into ordinary%

  • % S is a string type of accounting position

  • % D are numbers representing the type of location

  • Order of delivery location, occupancy, and fill bits must correspond to

    s = """ ------------- info -------------
    name:%s
    age:%s
    job:%s
    -------------- end -------------
    """
    name = input("name")
    age = int(input("age"))
    job = input("job")
    print(s%(name,age,job))
    
    # num = input("学习进度:")
    # s = "大哥黑的学习进度为:%s%%"
    # print(s%(num))
    
    # num = input("学习进度:")
    # num1 = input("aaaa:")
    # s = "大哥黑的学习进度为:%s%"
    # print(s%(num,num1))
    
    # num = input("学习进度:")
    # num1 = input("aaaa:")
    # s = "大哥黑的学习进度为:%s%s"
    # print(s % (num, num1))
  • Extended: f "{variable name} {string}" version 3.6 and above to use

    # s = f"今天下雨了{input('>>>')}"
    # print(s)
    
    # s = f"大黑哥的学习进度为{input('<<<')}"
    # # print(s)
    
    # s = f"{1}{2}{3}"
    # print(s)

Operators

Arithmetic Operators
  • / Addition ( {result} 5/2 result python2 is an integer, a decimal result python3)
  • // divisible (except flooring)
  • ** power (power)
  • % Modulus (remainder)
Comparison Operators
  • --- >
  • --- <
  • --- ==
  • --- !=
  • --- >=
  • --- <=
Assignment Operators
  • = Assignment
  • + = From Canada
  • - = Decrement
  • * = Squared
  • / = From the addition
  • //=
  • **=
  • %=
Logical Operators
  • and (with): the truth the whole truth,

    • We are really behind and take the time value
    • Are taken and the previous value is false when
    • Shinichi take a fake false value
    # print(3 and 4)
    # print(0 and 4)
    # print(0 and False)
    
    # print(3 and 5 and 9 and 0 and False)
    # print(5 and False and 9 and 0)
    # print(1 and 2 and 5 and 9 and 6)
  • or (or): it is a true true

    • Are true when the previous value or take
    • We have taken back or false value when
    • A really really worth taking a fake
    # print(1 or 0)
    # print(1 or 2)
    # print(0 or False)
    # print(1 or 9 or 4 or 0 or 9)
  • not (non): opposition

# print(not False)
  • 级别:()> not > and > or

  • Sequence: from left to right execution

    # print(9 and 1 or not False and 8 or 0 and 7 and False)
Member operator
  • in: there is
  • not in: does not exist
# s = "alexdsb"
# if "sb" not in s:
#     print(True)
# else:
#     print(False)

The initial coding

Code set (codebook)
# 今 0101
# 天 0110
# 晚 0010
# 上 0001
# 去 1001
# 便 1000
# 利 0100
# 店 1111
#
#
# 00000101  00000110  0010000110011001
  • ascii (United States): Does not support Chinese
  • GBK (National Standards codebook): English 8 bits (1 byte), Chinese 16 bits (2 bytes)
  • unicode (Unicode): English 16 (2 bytes), Chinese 32-bit (4-byte)
  • utf-8 (variable length coding, the most popular): English 8 bits (1 byte), text Europe 16 (2 bytes), Asian 24 bits (3 bytes)
  • linux system - utf-8
  • mac System - utf-8
  • windows system - gbk
  • Unit conversion:
    • A byte (1Bytes) = 8 bit (8bit)
    • 1024Bytes = 1KB
    • 1024KB = 1MB
    • 1024MB = 1GB
    • 1024GB = 1TB common
    • 1024TB = 1PB
    • 1024PB = 1EB

Guess you like

Origin www.cnblogs.com/NiceSnake/p/11140014.html