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]