day1-while loop

1  # repeat one thing 
2  # loop, iterate, iterate 
3  # Python in circulation, there are two: while and for 
4  # the while loop, you need to define a counter = 0 COUNT 
5  # break, inside the loop encounter break, cycle immediately ended 
. 6  # continue, inside the loop encounters continue, this cycle ends, the next cycle into the 
7  # guess, generate a random number 
8  # guess up to seven times 
. 9  Import random
 10 NUM = the random.randint (1,100 )
 . 11  Print (NUM)
 12 is COUNT = 0
 13 is  the while COUNT <. 7 :
 14      GUESS = int (INPUT ( 'Please enter a number: ' ))
 15      COUNT =. 1 +
 16      IF GUESS == NUM:
 . 17          Print ( " guessed, the game ends " )
 18 is          BREAK 
. 19      elif GUESS> NUM:
 20 is          Print ( " guess big game continues " )
 21          the continue 
22      the else :
 23          Print ( " guess small, and the game continues " )
 24-          the continue 
25  the else :
 26      Print ( " number guess is more than 7 times, the game is over")

 

Guess you like

Origin www.cnblogs.com/hujc/p/11716974.html