1.floor Division (this is only about division, others do not mention)
In Python3, there are two kinds of division operations, one is true, the other is floor division, and the two are separate, as shown in the code:
2. Use of power (* *)
A = 2**2**32= (2 **2) **32
3. For an even and odd number within 100, pay attention to the difference between the code.
# for an even number within 100 (inclusive)num = when num : if num% 2 :Print () Else: print(num) = num-1
# ask for an even number within 100 (not included) num = 100while Num:num = num-1 if num% 2: print () else : print (num)
# for an odd num = 100 or less num : = num-1 if num% 2: print
(num) Else: print()
4, find factorial
i = 1x= 7Flag=0 whileI < 100: I= i + 1if(x%2==1) and(x%3==2) and(x%5==4) and(x%6==5): Flag= 1Else: x= 7*IifFlag ==1: Print("the number of steps is:", X)Else: Print("please expand the range! ")
Elementary Turtle Source Code:
x = 7I= 1Flag=0 whileI <= 100: if(x%2 = = 1) and(x%3 = = 2) and(x%5 = = 4) and(x%6==5): Flag= 1Else: x= 7 * (i+1)#according to test instructions, x must be an integer multiple of 7, so multiply by 7 each time .i + = 1ifFlag = = 1: Print('the number of steps is:', X)Else: Print('can't find the answer within the limits of the program! ')
Little Turtle Python Video sixth lecture (after-school exercise)