From d8a3558daeca9de1d21182aaeb19c18dc9923f41 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Sat, 9 Feb 2019 15:12:08 -0500 Subject: [PATCH] Added prod() that multiplies all elements in a list together --- Algorithms.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Algorithms.py b/Algorithms.py index b90b9fb..75baf73 100644 --- a/Algorithms.py +++ b/Algorithms.py @@ -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