BugLab013 / 020up to 100
loopsaccumulatormatheasy

Zero Product

The function running_product(numbers) should return a new list where each element is the product of all elements up to and including that index.

So [2, 3, 4] should produce [2, 6, 24] — because 2, then 2×3=6, then 6×4=24.

Instead, it always returns a list of zeros, regardless of the input. The loop is correct. The logic is correct. There is one wrong starting value.

# your fix
+ must use for
hint 2after hint 1
hint 3after hint 2
solution

Read the code. Before running anything: what does the last line below give?

def running_product(numbers):
"""
Returns a new list where each element is the product of all elements
in `numbers` up to and including that index.
Example: [2, 3, 4] -> [2, 6, 24]
"""
result = []
product = 0
for n in numbers:
product *= n
result.append(product)
return result
>>> running_product([2, 3, 4])