Product of a list

EasyFunction Programs · 6 of 39

Write a Python function to multiply all the numbers in a list.

Advertisement
Input
[-8, 6, 1, 9, 2]
Output
-864

Approach

  1. Start at 1 and multiply.

Solution

Python
def product(numbers):    result = 1    for n in numbers:        result *= n    return result print(product([-8, 6, 1, 9, 2]))
Output
-864
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs