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 ("I Love You")
2. Observe the number of prints
i = 10while i > 0: print ("I Love You") i = i-1
Print 10 times ' I love you '
3. Note the usage of and (meaning both sides are true), write an expression equivalent to 10<a<19
< A < 1910 < A and a < 19
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.python3, can one line write multiple statements?
Can
Print (' asdf ');p rint (' asdf ')
6.python3, can a statement be divided into multiple lines of writing?
Yes, you can use backslashes or parentheses to break into lines
Print\
("HH")
7.and or
X or Y---if x is false,then y,else x
X and y--if x is false,then x,else y
Not x---If X if False and then true,else false
8. Note the condition in the while, that is, 0 is false
num = Int (input ("Please enter an integer:")) i = 0while num: i = i + 1 num = num-1 print (i)
Another elementary turtle's
temp = input (' Please enter an integer: ') number = Int (temp) i = 1while number: print (i) i = i + 1 number = Number-1
9. (Copy the Little Turtle)
temp = input (' Enter an integer: ') number = Int (temp) while number: i = number-1 while I: print (", end =") i = i -1 j = number while J: print (' * ', end = ') j = j-1 print () number = Number-1
10. (Copy the Little Turtle)
Import randomtimes = 3secret = Random.randint (1,10) print ('------------------I love fish C Studio------------------') # Here's The Guess assignment (assigning a value that is definitely not equal to secret) guess = 0# print () The default is to automatically add a line break when the string is printed, end= "" parameter tells print () to replace line with a space # Well, the Little turtle feels creative you should try End= "JJ"? Print ("Guess what number the little turtle is thinking Now:", end= ") while (guess! = secret) and (Times > 0): temp = input () guess = Int (temp) Times = times-1 # users Enter each time, the opportunity is 1 if guess = = secret: print ("My grass, are you the worm in the heart of the Little Turtle?!") print ("Hum, guess no reward!") else: If guess > Secret: print ("elder brother, Big Big ~ ~ ~") Else: print ("Hey, small, small ~ ~ ~") if times > 0: print ("Try again:", end= ") Else: print (" opportunity t_t ") print (" Game over, no play "^_^")
Little Turtle python Fourth talk