4-3 count to:Use a For loop to print the digital 1~20 (included)
As follows:
For numbers in range (1,21):
(space) print (numbers)
4-4 1 million: Create a list with numbers that contain 1~1000000, and then use a for loop to print the numbers.
As follows:
Numbers=[number for number in range (0,1000001)]
For number in numbers:
(space) print (number)
4-5 Calculate the sum of the 1~1000000: Create a list that contains the number 1~1000000, and then use min () and Max () to verify that the list is really starting from 1 and ending with 1000000. Also call the function sum () on this list to see how long it takes for Python to add 1 million numbers.
As follows:
Numbers=list (range (1,1000001))
Print (min (numbers))
Print (max (numbers))
Print (sum (numbers))
4-6 Odd: Specify the third argument by function range () to create a list that contains an odd number of 1~20, and then use a for loop to print the numbers.
Numbers=range (1,20,2)
For number in numbers:
(space) print (number)
Multiples of 4-7 3: Create a list that contains the number that 3~30 can be divisible by 3: Then use a For loop to print out the numbers in this list.
As follows:
Numbers=list (range (3,31,3))
For number in numbers:
(space) print (number)
4-8 Cubic: Multiply the same number by three times called Cubic. Included in Python, 2 cubic is represented by 23. Create a list that contains the first 10 integers (that is, 1~10), and then use a for loop to print the cubic numbers.
As follows:
Numbers=[number3 for number in range (1,11)]
Print (Numbers)
Python 4.3 Create a list of values (try it out)