Program to multiply all the numbers in a list

In this python function program, we will multiply all the numbers in a list.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function mul.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. list to the function.
  4. Create a variable and assign its value equal to 1.
  5. Use a for loop to iterate over the values in the list.
  6. After each iteration multiply the variable by the value.
  7. Print the output.
  8. Create a list and pass that list to the function while calling the function.
				
					def mul(list1):
    t = 1
    for val in list1:
        t *= val
    print("Product of elements in the given list: ",t)
    
l = [-8, 6, 1, 9, 2]
mul(l)
				
			

Output :

				
					Product of elements in the given list:  -864
				
			

Related Articles

find the sum of all the numbers in a list.

reverse a string

Leave a Comment