Python tuple program to multiply adjacent elements of a tuple

In this python tuple program, we will multiply adjacent elements of a tuple.

Steps to solve the program
  1. Create a tuple and an empty list.
  2. Create a tuple having adjacent elements as a tuple inside of a tuple using zip(tup,tup[1:]).
  3. Use for loop to iterate over this tuple.
  4. Now get the product of the adjacent element and add it to the empty list.
  5. Convert the list back to the tuple using tuple().
  6. Print the output.
				
					tup =  (1,2,3,4)
list1 = []
for a,b in zip(tup,tup[1:]):
    c = a*b
    list1.append(c)
tup = tuple(list1)
print("Multiplying adjacent elements: ",tup)
				
			

Output :

				
					Multiplying adjacent elements:  (2, 6, 12)
				
			

create a tuple having squares of the elements from the list.

1 thought on “Python tuple program to multiply adjacent elements of a tuple”

Leave a Comment