Added prod() that multiplies all elements in a list together

This commit is contained in:
Matthew Ellison
2019-02-09 15:12:08 -05:00
parent 6753a98502
commit d8a3558dae

View File

@@ -1,7 +1,7 @@
#Python/myClasses/Algorithms.py
#Matthew Ellison
# Created: 1-27-19
#Modified: 1-30-19
# Created: 01-27-19
#Modified: 02-09-19
#This is a file that contains a few algorithms that I have used several times
import math
@@ -186,3 +186,15 @@ def getAllFib(goalNumber: int) -> list:
#At this point the most recent number is > goalNumber, so remove it
fibNums.pop()
return fibNums
#This function returns the product of all elements in the list
def prod(nums: list) -> int:
#Setup the variables
product = 1 #Start at 1 because of working with multiplication
#Loop through every element in a list and multiply them together
for num in nums:
product *= num
#Return the product of all elements
return product