MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / getPrimeNumbers

Function getPrimeNumbers

other/primelib.py:112–135  ·  view source on GitHub ↗

input: positive integer 'N' > 2 returns a list of prime numbers from 2 up to N (inclusive) This function is more efficient as function 'sieveEr(...)'

(N)

Source from the content-addressed store, hash-verified

110# --------------------------------
111
112def getPrimeNumbers(N):
113 """
114 input: positive integer 'N' > 2
115 returns a list of prime numbers from 2 up to N (inclusive)
116 This function is more efficient as function 'sieveEr(...)'
117 """
118
119 # precondition
120 assert isinstance(N,int) and (N > 2), "'N' must been an int and > 2"
121
122 ans = []
123
124 # iterates over all numbers between 2 up to N+1
125 # if a number is prime then appends to list 'ans'
126 for number in range(2,N+1):
127
128 if isPrime(number):
129
130 ans.append(number)
131
132 # precondition
133 assert isinstance(ans,list), "'ans' must been from type list"
134
135 return ans
136
137
138# -----------------------------------------

Callers 1

goldbachFunction · 0.85

Calls 1

isPrimeFunction · 0.70

Tested by

no test coverage detected