CBSE Class 11 Computer Science Question 113 of 114

Tuples — Question 16

Back to all questions
16
Question

Question 14

Write a program to calculate the average of a tuple's element by calculating its sum and dividing it with the count of the elements. Then compare it with the mean obtained using mean() of statistics module.

Solution
import statistics 

tup = eval(input("Enter a tuple: "))
tup_sum = sum(tup)
tup_len = len(tup)

print("Average of tuple element is:", tup_sum / tup_len)
print("Mean of tuple element is:", statistics.mean(tup))
Output
Enter a tuple: 2,3,4,5,6,7,8,9,10
Average of tuple element is:  6.0
Mean of tuple element is:  6
Answer