Note: Writing programs cannot write repetitive code learning content: Data type, for loop, while loop, character encoding, file processing one, for loop 1, simple for loop for I in range (10): # Here's what it means: a set of data within a loop range, that is, looping 10 times Print (i) # Prints each time I value 2, for loop under simple guess age game #!/usr/bin/env python#-*-coding:utf-8-*-#-*-Coding:utf-8-*-oldboy_age = 40for I In range (4): guess_age = Int (input ("Enter guessing Age:") # defines the age data type if Guess_age ==oldboy_age:print ("Congratulations, guess right!") # guess right after you print the message break # guess right after you need the current bounce loop elif guess_age > Oldboy_age:print ("Sorry, guess big.") Else:print ("Sorry, guess small!") Else: # If the For loop ends normally, the statement under else is executed. Exit ("Operation full 4, loop over") print ("You're So Smart") Note 1: Multiple break is allowed in the loop, but once you jump out of the current loop, the program continues to go down and no longer returns. There is also the break can only be used in the loop, there is no loop when the break will be wrong. Note 2: Exit the Program: Exit () For example: to require the user to exit when the operation is repeated, you can add: Exit ("You have manipulated too many times to be forced to quit ... ") 3, for loop upgrade: Nested for loop for I in range: A for J in range (8): If J < 5: # Breaking break usage: jump out of the entire current layer loop, jumping only one layer continue # Co Ntinue usage: Jump out of the loop and continue to the next loop print (I,J)
Python Study the next day