From 44c89f144d4977a69b7c46ed0e92bd5daa78c51e Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Sat, 2 Mar 2019 13:54:44 -0500 Subject: [PATCH] Updated to fix a few small bugs --- Algorithms.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Algorithms.py b/Algorithms.py index 75baf73..f66ccb6 100644 --- a/Algorithms.py +++ b/Algorithms.py @@ -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 . +""" 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