WRITE A PROGRAM TO FIND THE AVERAGE OF THE ELEMENTS OF THE TUPLE.
Answers
Answer:
Explanation:
# Mean or average of tuple list
# Initializing tuple list
tuple = [(1, 4, 5), (7, 8), (2, 4, 10)]
# printing original list
print("The original tuple list is : " + str(tuple))
# Average of tuple list
# Using loops
sum = 0
for sub in tuple:
for i in sub:
sum = sum + i
res = sum / len(tuple)
# printing result
print("The mean of tuple list is : " + str(res))
def average_tuple(nums):
result = [sum(x) / len(x) for x in zip(*nums)]
return result
nums = ((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4))
print ("Original Tuple: ")
print(nums)
print("\nAverage value of the numbers of the said tuple of tuples:\n",average_tuple(nums))
nums = ((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3))
print ("\nOriginal Tuple: ")
print(nums)
print("\nAverage value of the numbers of the said tuple of tuples:\n",average_tuple(nums))