Notes and conditional (flow control statements) exercises

Note

  • For some obscure or interpreted code label
  • PEP8, can not exceed the specified line
1. 单行注释: # xxx

2. 多行注释: 
    """
    xxx
    """

3. ctrl+/  直接把圈起来的部分改成注释

Analyzing conditions (process control statements)

  • = Is the assignment;
  • == is equal;
  • ! = Is not equal to
  • : Means the end of the statement
  • Indent: 4 spaces = tab
  • tab and space can not be mixed, otherwise it is difficult to find errors
  • 1个IF,if+else,if+elif+elif, if+elif+else, if嵌套, if+if+if+if
  1. sex=input("请输入你的性别:")
    if sex == "girl":    
     print("come on,baby!")
    else:    
     print("go and find Xiaoming Huang, he is the same guy with you")
  2. sex=input("请输入你的性别:")
    if sex == "man":    
     print("bye")
    elif sex == "girl":    
     print("come on,baby!")
    else:    
     print("go and find Xiaoming Huang, he is the same guy with you")
  3. sex=input("请输入你的性别:")  man
    if sex == "girl":    
     print("come on,baby!")
    • if the statement is not necessary to keep else, such as 3 can not output.
  4. practice

    num=input("请输入你的年龄:")
    number=int(num)
    if number > 18 and number < 25:
        print("come on,baby!")
    else:
        print("That's not good")
    
    
    name=input("请输入你的名字:")
    password=input("请输入你的密码:")
    if name != "alex" or password != "oldboy":
        print("There is some wrong with your name or password!")
    else:
        print("land successfully")
    
    
    sex = input("请输入你的性别:")
    if sex == "man":
        print("go out and fuck yourself")
    else:
        age = int(input("请输入你的年龄:"))
        if age <= 25:
            print("hello")
        else:
            print("sorry,i`m so tired.")
    print("that`s a good night")
    • ! = Is py3 of inequality
    • Else if there is, then there will certainly be an output, ie, the "alternative"

  5. if nested

    • If the condition:

    • If the condition indent:

      Indent results

  6. if if if

    constant

    • Constants: variable name capitalization is constant. (In the definition of non python, the python constants do not exist) eg: ID
    • You may be modified, but do not change as much as possible
    • For the configuration file

Guess you like

Origin www.cnblogs.com/Guoxing-Z/p/11469525.html