mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Added function to test if a number is prime
This commit is contained in:
@@ -97,6 +97,17 @@ def getNumPrimes(numberOfPrimes: int) -> list:
|
||||
#Return the list with all the prime numbers
|
||||
return primes
|
||||
|
||||
#This function determines whether a number is prime
|
||||
def isPrime(possiblePrime: int) -> bool:
|
||||
if(possiblePrime <= 3):
|
||||
return possiblePrime > 1
|
||||
elif(((possiblePrime % 2) == 0) or ((possiblePrime % 3) == 0)):
|
||||
return False
|
||||
for cnt in range(5, int(math.sqrt(possiblePrime)) + 1, 6):
|
||||
if(((possiblePrime % cnt) == 0) or ((possiblePrime % (cnt + 2)) == 0)):
|
||||
return False
|
||||
return True
|
||||
|
||||
#This is a function that returns all the factors of goalNumber
|
||||
def getFactors(goalNumber: int) -> list:
|
||||
prime_factors_list = []
|
||||
|
||||
Reference in New Issue
Block a user