python3.5 use
Day Sixth:
Now let's talk about the use of the For loop
Write a piece of code to explain it first:
1 for in range:2 print(i)
The first paragraph means that the loop I (variable) starts from 0 printing can only be printed 10 times
So when we're going to print I will print 10 times from 0 to 9
The last time you guessed the number, you could use for to optimize it.
1Number=232 forIinchRange (3):3Guess_age=int (Input ("Number :"))4 ifguess_age==Number :5 Print("Yes,you got it.")6 Break7 elifGuess_age>Number :8 Print("think smaller ...")9 Else:Ten Print("Think bigger!") One Else: A Print("You have tricd too many times.")
Careful comrade must have found that else did not appear in pairs with if, last time I said else means "other"
If it's not, it's the same, it's the other way around in the loop.
Let's continue to see the for statement
1 for in range (0,10,2):2 print(i)
is not printed 0,2,4,6,8 these numbers ah, in the code that the 0 represents starting from 0, 10 represents the end of 10, the following 2 represents a jump 2 number.
What's the point, I'm going to tell you, for example, I'm asking 0 to 8648 in the middle is 1243 of the full number of multiples is not immediately get ah, programming charm is this.
For in-depth usage:
When the for encounters if:
Write a program to understand it
for in range :print(i )if i<5: Print ('Huang')
Print out 10 numbers 5 "Hung" is not found only 0 to 4 followed by "Huang" because he executed the judgment he is a number a number of the loop when the loop to 5 when the if is not executed so there is no
Python (vi) Basic learning because there are so many deficiencies in the front, there's less here, but I'm still going to send it.