Process control language python

Process Control

1.python statement free
2. Related free process control
3. sequence structure
4. branch structure
5. cyclic structure
6. Other process control statements


Classification 1.python statement

1. The single line of code line of python code

2. The block / group:
colon as the start, with the same indentation dividing scope such a configuration called a code block as a whole.
Scope refers to the scope. The role of the region, using the same indentation that have the same scope.
Indent: a table distance or four spaces.
Note: Block / group Table strict distinction space and, not mix, indents must use only one!


2. The flow control free
flow of control: control of the process control computer code is executed.
Classification: a branch structure 2. Structure of the sequence / structure 3. Select cyclic structure

3. The structure of the order
sequence structure is the default program structure, a top-down performed

4. A branch structure
structure of the code
1. Individually branch if conditional expression: a python code a python code a python code ... 2. Odd branch if conditional expression: a python code a python code a python code .. . the else: a python code a python code a python code ... 3. The number of branches if the conditional expression: a python code a python code a python code ... elif conditional expression: a python code a python code a python code ... elif conditional expression: a python code a python code a python code ... ... the else:





































A python code
a python code
a python code
... 4. The apparatus nest branch (branch nested structure) example: if conditional expression: code statement if the conditional expression: code statement else: code statement else: code statement 5 . single line branches example: variable interval = true else if true value false 5. cyclic structure must be familiar! # 3 described a cock 33 1--33 # 1 described a 100 Hen 1--100 # 0.5 chick paper a 200 1 - 200 is man_chick = 1 Zhong = 0 the while man_chick <34 is: # (value rooster) hEN. 1 = # (. 1 hen =) the while hEN <101: # (hens value) child_chick. 1 = # (. 1 chick =) the while child_chick <200 is: # (chick value)


























HEN man_chick + + child_chick IF == * man_chick 100 and 3 + HEN + 0.5 * child_chick == 100:
# (+ rooster hen chicks == + + money to buy a rooster hen money to buy chickens money to buy == + 100 )
Print ( "rooster:", man_chick, "hen:", hen, "chicken:" child_chick)
Zhong + =. 1
child_chick + =. 1
hEN + =. 1
man_chick + =. 1
Print ( "a kind of", zhong, "method")

a.while circulating
the basic structure:
: the while conditional expressions
Code Description
Code Description
Code Description
... cycling conditions with varying 1. declare variable var Analyzing 2.while be of var: Code content Code Description Code Description ... 3. the changing operation of var b.for..in cycle (mainly containers for traversing data) for the container in custom variable data: Code content, can use custom variables Code contents you can use custom variables Code content,You can use custom variables















Application else statement
branch else statement first appeared in circulation else statement can be used while a conditional expression: Loops Loops Loops ... else: code statement code statement code statement ... other flow control statements 1.break statement 2.continue statement 3.pass statement special statement: 1.exit () 2.quit () execution for the end of the program, exit () and quit the code (after) will not be executed. Role and break in a simple loop structure like, but must not be confused! ! !



















Guess you like

Origin www.cnblogs.com/www-123/p/11116183.html