Python 4.3 Create a list of values (try it out)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.