mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Fixed problem with getFactos that always adds goalNumber to factors
This commit is contained in:
@@ -41,8 +41,6 @@ def getFactors(goalNumber: int):
|
||||
primes = getPrimes(math.ceil(math.sqrt(goalNumber))) #If there is a prime it must be <= sqrt(num)
|
||||
factors = []
|
||||
|
||||
#If you didn't get any primes the number itself must be a prime
|
||||
factors.append(goalNumber)
|
||||
#You need to step through each prime and see if it is a factor in the number
|
||||
cnt = 0
|
||||
while((cnt < len(primes)) and (goalNumber > 1)):
|
||||
@@ -55,6 +53,10 @@ def getFactors(goalNumber: int):
|
||||
else:
|
||||
cnt += 1
|
||||
|
||||
#If you didn't get any factors the number itself must be a prime
|
||||
if(len(factors) == 0):
|
||||
factors.append(goalNumber)
|
||||
|
||||
#If for some reason the goalNumber is not 0 print an error message
|
||||
if(goalNumber > 1):
|
||||
print("There was an error in getFactors(). A leftover of " + str(goalNumber))
|
||||
|
||||
Reference in New Issue
Block a user