One: summary of key points of knowledge
1. Python output and input function----print (), input ()
2. Conditional judgment----if else, elif
3. Loop----while, for
Two: Python the output and input functions
1. Python's output function: print () #打印输出
Print () Prints the output string, integer, numeric calculation result, and encounters a comma "," to output a space.
Example: >>> print ("Hello world!")
Hello world!
>>> print ("Hello, world! ")
Hello, world!
>>> print ("100")
100
>>> Print (100+200)
300
>>> print ("Hello world!", "100")
Hello world! 100
2. Input function of Python: input ()
The input () function allows the user to enter a string and store it in a variable.
For example:>>> name = input ("Please enter your name:")
Please enter your name:
When you enter name = input ("Please enter your name:") and press ENTER, the python interactive command line is waiting for your input. At this point, you can enter any character and then press ENTER to complete the input. Once the input is complete, the input is stored in the variable name .
We can print out the name using print ().
For example: name = input ("Please enter your name:")
Print (name)
Three: Conditional Judgment
The conditional judgment statement in Python is the If else, which is executed as follows:
--------------------------------------------------
If < conditions 1>:
Perform 1
Else
Perform 2
-----------------------------------------------------
This means that if the IF statement evaluates to TRUE, the indented statement is executed. If the If judgment is false, the content of the if is not executed, and the else content is executed.
For example:
Name = "Jack"
Password = "King"
name1 = input ("please Input your usename: ")
password1 = input (" Please input your Password: ")
if name1 = = Name and Password1 = = password:
Print ("Well done ...")
Else
Print ("wrong!!")
If you want the if to judge a bit more complex, you can use the Elif statement, Elif is the else if abbreviation, its execution form is as follows:
--------------------------------------------------------------
If < conditions 1>:
Perform 1
elif< condition 2>:
Perform 2
elif< condition 3>:
Perform 3
Else
Perform 4
---------------------------------------------------------------
This means that if the IF statement evaluates to TRUE, the indented statement is executed. If the If judgment is false, the content of the elif is judged. Plainly, that is, if the condition 1 satisfies, executes 1, if the condition 1 is not satisfied, determines whether the condition 2 satisfies, and so on. If none are satisfied, the else judgment is executed.
For example:
Name = "Jack"
Password = "King"
name1 = input ("Please input your username:")
Password1 = input ("Please input your password:")
If name1 = = Name and Password1 = = password:
Print ("Well-done ...")
elif name1 = = Name and Password1! = password:
Print ("Bad password!") ")
Elif name1! = Name and Password1 = = password:
Print ("User name Error! ")
Else
Print ("User name or password is wrong!") ")
Four: While Loop and for Loop
1. The While loop statement is used to loop the execution of a program that, under certain conditions, loops through a program, exits the loop when the condition is false, and executes the statement following the body of the loop.
For example:
A = 0
While a < 5:
Print (a)
A +=1
Let's write a slightly more complex while loop, such as:
Age = 12
Count = 0
While count<3:
age1 = Int (input ("Please input your Age:"))
if Age1 = = Age:
Print ("good")
Break
Elif Age1 > Age:
Print ("bigger")
Else:
Print ("Smaller")
Count +=1
2. For Loop statement. The For loop is in the form of : for x in ...
例如:
Age = A
For ainchRange (3):
Age1 =Int (Input ("Please input your Age:"))
if age1 = = age:
Print ( "good")
Span style= "color: #000080; Font-weight:bold ">break
elif age1 > age:
print ( Span style= "color: #008080; Font-weight:bold ">" bigger ")
else:
print ( < Span style= "COLOR: #ff0000" > "Smaller")
===============================================================================================
Summary: Learn slowly, the road resistance and long, the line will be to.
Python Learning----Day1