Program to calculate the average of the elements in the tuple

In this python tuple program, we will calculate the average of the elements in the tuple.

Steps to solve the program
  1. Take a tuple as input and create a variable add and set its value equal to 0.
  2. Use a for loop to iterate over numbers in the tuple.
  3. Add the numbers to the add variable.
  4. Find the average of the elements in the tuple by dividing the value of add variable by the length of the tuple i.e number of elements in the tuple.
  5. Print the output.
				
					tup = (5,3,9,6)
print("Original tuple: ",tup)
add = 0
for ele in tup:
    add += ele
print("Average of elements in the tuple: ",add/len(tup))
				
			

Output :

				
					Original tuple:  (5, 3, 9, 6)
Average of elements in the tuple:  5.75
				
			

count the total number of unique tuples.

program to swap tuples.

Leave a Comment