1while statement, when the condition is true, it will continue to loop, such as the following example, but can be used ctral + C to force the end
while ' C ' : print ("iLove you")
2. Observe the number of prints
Ten while 0 : print ("iLove you") 1
3. Note the usage of and (meaning both sides are true)
Ten + Ten +
4. Short Circuit logic
Generally speaking, the short circuit logic is worth in a logic, only the first half of the judgment, as long as the first half can determine the result, it will not judge the second half of the logic.
5. Note the condition in the while, that is, 0 is false
num = Int (input (" Enter an integer:"= 0 while num: = i + 1 = num-1 Print (i)
6.
temp = input ('Please enter an integer:') number=Int (temp) whilenumber:i= Number-1 whileI:Print(' ', end ="') I= I-1J= Number whileJ:Print('*', end ="') J= J-1Print() number= Number-1
7. (Copy the Little Turtle)
ImportRandomtimes= 3Secret= Random.randint (1,10)Print('------------------I love fish C studio------------------')#Here's The Guess assignment first (assigning a value that is definitely not equal to secret)Guess =0#Print () By default, a newline character is automatically added when the string is printed, and the end= "" parameter tells print () to use a space instead of a newline .#Well, the Little turtle feels creative you should try to use end= "JJ"? Print("guess which number the turtle is thinking now:", end=" ") while(Guess! = secret) and(Times >0): Temp=input () Guess=Int (temp) times= Times-1#every time the user enters, the available opportunity is 1 ifGuess = =Secret:Print("I grass, you are a small turtle in the heart of the worm?! ") Print("Well, there's no reward for guessing! ") Else: ifGuess >Secret:Print("elder brother, Big has been big ~ ~ ~") Else: Print("Hey, small, small.") ifTimes >0:Print("Try it again:", end=" ") Else: Print("The opportunity t_t")Print("game Over, no play ^_^")
Little Turtle Python Video IV lecture (after-school exercise)