Cycle: While,for
For loop:
For I in Range (0,10,2):
Loop body
Note: Range inside the 2, is the step, that is, I value is: 0, 2,4,6,8; default is 1,for I in range (Ten) ==for I in range (0,10) ==for I in range (0,10,1)
End loop: Break: End Current Loop
Continue: Jump out of the loop and into the next loop
Write a loop: Guess the size of a number
Idea: Give a number to guess the size, when guessing the number is greater than the given number, return to guess the number is too large; When the guessed number is less than the given number, then return the guessed number is too small, when the guessed number equals the given number, then returns the success
The number of guesses is limited to 3 times, when the third guess is wrong, ask whether to continue guessing the word game, when the input is not ' n ' and ' n ', you can continue to guess three times.
good_number=57
Guess_count=0
While guess_count<3:
Guess_number=int (Input (' Please input your guess_number: '))
If Guess_number==good_number:
Print (' Good!!! You got it!!! ')
Break
Elif Guess_number<good_number:
Print (' Too bad!!! You guessed it is small. ')
Else
Print (' Too bad!!! You guessed it is big. ')
Guess_count+=1
If guess_count==3:
Print (' guessed wrong three times,do you want to keep guessing ... ')
Continue_game=input (' If you want-continue playing,you can enter any character or enter directly;\n '
"If you don't want to continue playing, please enter ' n '. \ nthe")
If continue_game!= ' n ' and continue_game!= ' n ':
Guess_count=0
The Python loop 1