Python exercise 008: print all prime numbers between 101-200, python101-200

Source: Internet
Author: User

Python exercise 008: print all prime numbers between 101-200, python101-200

[Python exercise question 008]Determine the number of prime numbers between-and output all prime numbers.

---------------------------------------------------------------------

This is a separate question. It is said that there are many solutions. My idea is: first create an integer list of-, and then make a judgment. If a number can be divisible by "from 2 to the first digit", the number will be removed from the list. One by one, the rest are prime numbers. The Code is as follows:

Lst = [] for I in range (100): # create a list of 101-200 lst. append (101 + I) for I in range (101,201): # The divisor is 101-200. These 200 numbers for j in range (2, I ): # The divisor is the first digit from 2 to I. if I % j = 0: # if the remainder is exceeded. remove (I) # remove breakprint (lst) from the lst list # The rest are prime numbers.

The output result is as follows:

[101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199]

 

++

Source: getting started with programming languages: 100 typical examples [Python]

Related Article

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.