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)
| 124 | |
| 125 | |
| 126 | def 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 | # ----------------------------------------- |