Notes 02 review process statements and jump statements

       python flow control statements 
python three flow control statements structure 1, the structure of the order of 2, 3 select statement, a loop statement
1, is a sequence of statements to perform a write down the code in accordance with
2, is based on the select statement to execute conditional statements branch
3, a loop condition is to give the condition loop is executed after the block of statements to be executed
sequentially statement simply much description line by line down the implementation of
selected blocks expression statement if
the statement block of the second row, for example, to perform write:
a = 5 \ # single condition is determined
if a> 0: # behind the block of statements is missing punctuation may not
print ( 'do you want to do')
# many conditions Analyzing
a = 5 # variable is set to a value of 5
the while True: # setting a first cycle
b = int (input ( 'enter your numbers')) # guessed by a user input digital
if b <a: # b judgment statement following statement is executed is smaller than a
Print (' too small ')
: elif b> a # the following statement is determined when the statement is executed b is greater than a
') Print ( 'too
: # following statement is executed when judgment statement elif b == b equals a a
Print (' guessed ' )
Analyzing statements can be nested been determined that is a statement can have N and B is determined in block B is determined and statements may have N and C in the decision statement of the N D C has been determined nested

while loop
while loop means a set of statements to be executed repeat been implementing be careful careful to enter an infinite loop consuming when # using the while statement memory
such as:
Print ( 'now there is a thing unknown number, left two hundred thirty-three number, the Find the number remaining three seventy-seven the number of the remaining two, geometry ask?
')
number = 0
# counting variable
none = True
the while none: # set a loop out of the loop until the condition is not satisfied
nomber + =. 1
IF nomber == 2%. 3 and nomber % 5 == 3 and nomber% 7 == 2: # conditions are selected to satisfy the following execution conditions are satisfied statement block
print ( 'answer: this number is', number)
none = False


for cycle # this loop most commonly used
for a circulation loop is repeatedly executed in sequence, generally used in the traversal sequence, and an iterative object elements
for i in the object: example: the following Examples 99 to print a multiplication table for loop

print ( 'multiplication table')
for X in range (1,10): # first Substituting the number of target loop 10
for y in range (1, x + 1):
Print (STR (Y) + '*' + STR (X) + '=' + STR (X * Y), End = '' ')
Print (' ')


jump statements
BREAK (end of cycle) Continue (out of this cycles)
BREAK direct to end the current cycle is out of round continue the cycle begins the next cycle also pass an empty statement is nothing more than a placeholder

Guess you like

Origin www.cnblogs.com/yexingyi/p/11165771.html