BugLab020 / 020up to 100
functionsargsunpackingmedium

The Ignored Stars

The function product_of_list(numbers) should return the product of all numbers in a list. It delegates the actual multiplication to a helper multiply_all(*args), which takes individual numbers as separate arguments.

It never crashes, but product_of_list([2, 3, 4]) returns [2, 3, 4] instead of 24. The helper multiply_all is correct, so the bug is in how product_of_list calls it.

Can you spot the one missing character?

hint 2after hint 1
hint 3after hint 2
solution

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

def multiply_all(*args):
"""Helper: returns the product of all its arguments."""
result = 1
for n in args:
result *= n
return result
def product_of_list(numbers):
"""
Returns the product of all numbers in a list.
Uses multiply_all internally.
Example: product_of_list([2, 3, 4]) -> 24
"""
return multiply_all(numbers)
>>> product_of_list([2, 3, 4])