The second loop logic and python

A logic determination

1 using the judgment condition in the if else to colon

 

 

Results of operation

 

 

 

 

 

 

 2 if elif else used in the case of multiple determination

 

 

operation result:

 

 

 

 

 Second, circulation

1.while cycle

The above example, we optimized only guess three times, if not three times guess guess not let continue, and if guessed it, on the termination of the cycle (while break)

 

 

 operation result:

 

 

 

 

 

Again a wayward point, when the wrong three times, asking the user whether to continue playing, if you continue to play it, if you do not play, then quit

2.for cycle

J represents the number of cycles; for example, into a loop for the above, the syntax for i in range (j); where i is the temporary variable from zero (of course, can specify the start position)

 

 

specify the starting position for the cycle, print 1,3,5,7,9

 

 

 operation result

 

 

 Divisible by 3 numbers between 1-20 Print

 

 

 

 

 

 By these two examples, we can see that the range (i, j, k) i and j represent the start and end positions, k represents a step

 

In the example above we use the break is over the whole cycle, that is to continue there is a corresponding jump out of this cycle, the next cycle continues

 

Guess you like

Origin www.cnblogs.com/axiangstudy/p/11521885.html
Recommended