## Saturday, September 12, 2020

Solution Exercise 515 : python algorithm to determines the list of prim numbers from given an integer m to an integer n

#### Exercise 515

Write a python program which determines the list of prime numbers from m to n for given two integers m and n such that m < n

#### Solution

``````# create a function to test primality of given number
def primNumber(n):

# initializing  the number of divisors of n
numberOfDivisors = 0
for i in range(1 , n+1):
if n%i == 0:
numberOfDivisors = numberOfDivisors + 1
if numberOfDivisors == 2:
return True
else:
return False

def listPrim(m , n):
# Initialising the searched list
listSearch = []
# the number m must be smaller than n
for i in range(m , n + 1):
if primNumber(i) == True:
listSearch.append(i)
return listSearch

# Testing algorithm
print("The searchd list for m = 1000 and n = 2000 is : " , listPrim(1000, 2000))
``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 