Python Practice › Function Programs › Program 6
Product of a list
Write a Python function to multiply all the numbers in a list.
Input
[-8, 6, 1, 9, 2]
Output
-864
Approach
- Start at 1 and multiply.
Solution
def product(numbers): result = 1 for n in numbers: result *= n return result print(product([-8, 6, 1, 9, 2]))Output
-864
Learn the concept
New to this topic? Read the lesson, then come back.