Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """This function calculates the product of all numbers in a list """
- # The function is named product() and it has accept a list of numbers
- def product(numbers):
- if len(numbers) > 0:
- multiply = 1 # Setting the base of the multiplication
- for number in numbers:
- multiply *= number # Multiply the iterated numbers
- return multiply
- print(product([1, 2, 3])) # 6
- print(product([4, 5, 6, 7])) # 840
- print(product([10])) #10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement