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
Write a recursive function to add the first 'n' terms of the series:
1 + 1/2 - 1/3 + 1/4 - 1/5……………
Write a program to find the greatest common divisor between two numbers.
Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number whose factorial is to be calculated as the argument.
Write a Python function that takes a number as a parameter and checks whether the number is prime or not.