Write A Python Program To Multiplies All The Items In A List

Hi Guys, welcome to my blog in this article you will learn about how to Write A Python Program To Multiplies All The Items In A List

 

Title : 

Write A Python Program To Multiplies All The Items In A List


Write A Python Program To Multiplies All The Items In A List



 

Description : 

Hi guys, in this article you will learn a python program to accept a number from the user and find product of all the numbers present in list of numbers First take a length variable and ask a user to enter the length of the list of numbers. Now iterate from 0 to the list length and ask the user to enter a number and then append to the list of numbers. This is the method to accept a numbers and the user


    
length = int(input("Enter The Length of Numbers List : "))
numbers = []
for index in range(length):
   temp = int(input(f"Enter {index+1} Number : "))
   numbers.append(temp)


    


take a product variable and initialize it to one, this variable will be used to store the product of all the items in list. use the for loop to iterate all the items present in the numbers list and multiply it to the product variable.


    
product = 1
for item in numbers:
   product *= item


    


Finally use the print function call to print the product of all the n numbers accepted from the user.


    
print(f"Product of All the Items in a List id : {product}")


    




Complete Python Code : 


    
length = int(input("Enter The Length of Numbers List : "))
numbers = []
for index in range(length):
   temp = int(input(f"Enter {index+1} Number : "))
   numbers.append(temp)

product = 1
for item in numbers:
   product *= item

print(f"Product of All the Items in a List id : {product}")


    

 

 

Output : 


    
Enter The Length of Numbers List : 5
Enter 1 Number : 1
Enter 2 Number : 2
Enter 3 Number : 3
Enter 4 Number : 4
Enter 5 Number : 5
Product of All the Items in a List id : 16


    

 

Output : 


    
Enter The Length of Numbers List : 3
Enter 1 Number : 12
Enter 2 Number : 45
Enter 3 Number : 90
Product of All the Items in a List id : 148



    



Conclusion :

The above Python program accepts n numbers from the user and appends it to an empty list of numbers. Iterates all the numbers using a for loop, then finds the product and prints it on to the standard output. Comment it down below if you have any suggestions to improve the above Python program

 

Post a Comment

0 Comments