1. String Integration:
+ No spacing of output results
, spacing of output results
2. Arithmetic operators:
divisible
% Take remainder
* * prescribe
! = does not equal
3. Assignment operators:
A+=1 equivalent to a+1, a*=2 equivalent to a*2
4. Logical operators:
and tie relationships
or or
not non-
Priority:Not>and>or
Short-circuit principle: in two conditions to determine the condition 1, sometimes no longer need to look at other conditions
5. output 1 to All even numbers:
A=1
While a<50:
If a%2==1:
A+=1
Else
Print (a)
A+=1
Print ("End")
6, give the reminder cycle guess Age:
Age=50
Flag=true Adding a state variable
While flag:
Guess=int (Input ("Guess Age:"))
If Guess==age:
Print ("right!")
Flag=false Correct seasonal state variable to jump out while loop
Elif Guess>age:
Print ("Too big")
Else
Print ("Too small")
Print ("End")
7. Other directives:
Break Terminate Loop
Continue jump out of the loop
End= "_" takes _ as the end of the sentence and does not break the line
Print () represents print (end= "\ n"), which is a newline
The else statement after the while is run when the while is at a normal end, that is, When there is no break
8, According to user demand output line and width:
H=int (Input ("Height:"))
W=int (Input ("width:"))
Nh=1
While Nh<=h:
Nw=1 width must be changed once per line, so it is placed within the while loop
While Nw<=w:
Print ("#", end= "")
Nw+=1 across the line.
Print () line break
Nh+=1
Note: Nesting loops, writing simple loops, and substituting ideas into another loop
9, 99 multiplication table:
Hang=1
While hang<=9:
Lie=1
While Lie<=hang:
Print (str (LIE) + "*" +str (hang) + "=" +str (Lie*hang), end= "\ T")
Lie+=1
Print ()
Hang+=1
Note: the connection of strings;"\ t" means tab; Use tab instead of space to make the table neat
Python notes---day2:while loops