Python tuple program to multiply all the elements in a tuple

In this python tuple program, we will multiply all the elements in a tuple.

Steps to solve the program
  1. Take a tuple as input.
  2. Create a variable named product and assign its value equal to 1.
  3. Use a for loop to iterate over each number in the tuple.
  4. During iteration multiply the product variable with each number in the tuple.
				
					tup = (5,4,3,1)
print("Origianl tuple: ",tup)
product = 1
for val in tup:
    product *= val
print("Multiplication of elements in the tuple: ",product)
				
			

Output :

				
					Origianl tuple:  (5, 4, 3, 1)
Multiplication of elements in the tuple:  60
				
			

count the elements in a list if an element is a tuple.

convert a string into a tuple.

Leave a Comment