mirror of
https://bitbucket.org/Mattrixwv/pyclasses.git
synced 2025-12-06 18:33:58 -05:00
Added prod() that multiplies all elements in a list together
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#Python/myClasses/Algorithms.py
|
#Python/myClasses/Algorithms.py
|
||||||
#Matthew Ellison
|
#Matthew Ellison
|
||||||
# Created: 1-27-19
|
# Created: 01-27-19
|
||||||
#Modified: 1-30-19
|
#Modified: 02-09-19
|
||||||
#This is a file that contains a few algorithms that I have used several times
|
#This is a file that contains a few algorithms that I have used several times
|
||||||
|
|
||||||
import math
|
import math
|
||||||
@@ -186,3 +186,15 @@ def getAllFib(goalNumber: int) -> list:
|
|||||||
#At this point the most recent number is > goalNumber, so remove it
|
#At this point the most recent number is > goalNumber, so remove it
|
||||||
fibNums.pop()
|
fibNums.pop()
|
||||||
return fibNums
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user