mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Fixed a but where 2 was not being added to the prime numbers
This commit is contained in:
@@ -14,10 +14,10 @@ def getPrimes(goalNumber: int):
|
|||||||
#If the number is 0 or negative return an empty list
|
#If the number is 0 or negative return an empty list
|
||||||
if(goalNumber <= 1):
|
if(goalNumber <= 1):
|
||||||
return primes
|
return primes
|
||||||
|
#Otherwise the number is at least 2, therefore 2 should be added to the list
|
||||||
#If the number is even 2 is a factor and all other factors will be odd
|
else:
|
||||||
if((goalNumber %2) == 0):
|
|
||||||
primes.append(2)
|
primes.append(2)
|
||||||
|
|
||||||
#We can now start at 3 and skip all even numbers, because they cannot be prime
|
#We can now start at 3 and skip all even numbers, because they cannot be prime
|
||||||
for possiblePrime in range(3, goalNumber + 1, 2): #Need goalNumber + 1 to account for goalNumber being prime
|
for possiblePrime in range(3, goalNumber + 1, 2): #Need goalNumber + 1 to account for goalNumber being prime
|
||||||
#Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor
|
#Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor
|
||||||
|
|||||||
Reference in New Issue
Block a user