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)
| 110 | # -------------------------------- |
| 111 | |
| 112 | def 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 | # ----------------------------------------- |