In this program, we will take a user input as a list & iterate all the values one by one with the python loop to find the product of all elements in a list with the help of the below-given steps.
Table of Contents
Method 1: Using for loop
Steps to solve the program
- Take a list as input.
- Using for loop with the necessary condition find the product of all elements in a list.
#Input list
list1 = [3,6,9,2]
#Creating variable
var = 1
for value in list1:
var *= value
#Printing output
print(var)
Output :
324
Method 2 : Using while loop
Steps to solve the program
- Take a list as input.
- Use while loop with the necessary conditions to find the product of all elements of the list.
#Input list
list1 = [3,6,9,2]
#creating variables
product = 1
count = 0
while count < len(list1):
product *= list1[count]
count += 1
#Printing output
print(product)
Output :
324
Related Articles
Python program to find the minimum and maximum elements from the list.
Python program to differentiate even and odd elements from the given list.
Python program to remove all duplicate elements from the list.
Python program to print a combination of 2 elements from the list whose sum is 10.
Python program to print squares of all even numbers in a list.
1 thought on “4. Problem to get product of all elements in a list”