Multiplication of Numbers in a List

Write a Python function that takes a list of numbers as input and returns the product of all the numbers in the list.

Example 1:

Input: [1, 2, 3, 4, 5] 
Output: 120

Example 2:

Input: [6, 7, 2, 0, 1] 
Output: 0

Use a loop to iterate through the list.

def multiply_numbers(lst):
    result = 1
    for num in lst:
        result *= num
    return result

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!