mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Updated to fix a few small bugs
This commit is contained in:
@@ -3,11 +3,27 @@
|
||||
# Created: 01-27-19
|
||||
#Modified: 02-09-19
|
||||
#This is a file that contains a few algorithms that I have used several times
|
||||
"""
|
||||
Copyright (C) 2019 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
import math
|
||||
|
||||
#This function returns a list with all the prime numbers <= goalNumber
|
||||
def getPrimes(goalNumber: int):
|
||||
def getPrimes(goalNumber: int) -> list:
|
||||
primes = []
|
||||
foundFactor = False
|
||||
|
||||
@@ -44,7 +60,7 @@ def getPrimes(goalNumber: int):
|
||||
return primes
|
||||
|
||||
#This function gets a certain number of primes
|
||||
def getNumPrimes(numberOfPrimes: int):
|
||||
def getNumPrimes(numberOfPrimes: int) -> list:
|
||||
primes = []
|
||||
foundFactor = False
|
||||
|
||||
@@ -87,10 +103,9 @@ def getNumPrimes(numberOfPrimes: int):
|
||||
|
||||
#Return the list with all the prime numbers
|
||||
return primes
|
||||
|
||||
|
||||
#This is a function that returns all the factors of goalNumber
|
||||
def getFactors(goalNumber: int):
|
||||
def getFactors(goalNumber: int) -> list:
|
||||
#You need to get all the primes up to this number
|
||||
primes = getPrimes(math.ceil(math.sqrt(goalNumber))) #If there is a prime it must be <= sqrt(num)
|
||||
factors = []
|
||||
@@ -189,6 +204,10 @@ def getAllFib(goalNumber: int) -> list:
|
||||
|
||||
#This function returns the product of all elements in the list
|
||||
def prod(nums: list) -> int:
|
||||
#If a blank list was sent to the function return 0 as the product
|
||||
if(len(nums) == 0):
|
||||
return 0
|
||||
|
||||
#Setup the variables
|
||||
product = 1 #Start at 1 because of working with multiplication
|
||||
|
||||
|
||||
Reference in New Issue
Block a user