In this python tuple program, we will multiply all the elements in a tuple.
Steps to solve the program
- Take a tuple as input.
- Create a variable named product and assign its value equal to 1.
- Use a for loop to iterate over each number in the tuple.
- 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