Computer Science

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

Sample List: (8, 2, 3, -1, 7)
Expected Output : -336

Python

Python Functions

2 Likes

Answer

def multiply_list(numbers):
    product = 1
    for num in numbers:
        product *= num
    return product

numbers = eval(input("Enter the list: "))
product = multiply_list(numbers)
print("The product of the numbers in the list is", product)

Output

Enter the list: [8, 2, 3, -1, 7] 
The product of the numbers in the list is -336


Enter the list: [1, 6, 3, 5]  
The product of the numbers in the list is 90

Answered By

2 Likes


Related Questions