MCPcopy Index your code
hub / github.com/geekcomputers/Python / getPrimeNumbers

Function getPrimeNumbers

primelib/primelib.py:126–147  ·  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

124
125
126def getPrimeNumbers(N):
127 """
128 input: positive integer 'N' > 2
129 returns a list of prime numbers from 2 up to N (inclusive)
130 This function is more efficient as function 'sieveEr(...)'
131 """
132
133 # precondition
134 assert isinstance(N, int) and (N > 2), "'N' must been an int and > 2"
135
136 ans = []
137
138 # iterates over all numbers between 2 up to N+1
139 # if a number is prime then appends to list 'ans'
140 for number in range(2, N + 1):
141 if isPrime(number):
142 ans.append(number)
143
144 # precondition
145 assert isinstance(ans, list), "'ans' must been from type list"
146
147 return ans
148
149
150# -----------------------------------------

Callers 1

goldbachFunction · 0.85

Calls 2

isPrimeFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected