Q. Write a program to calculate the average of a tuple 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.

Answer :-

import statistics 
tup = eval(input("Enter a tuple :-"))

sum = sum(tup)
print("Average =", sum / len( tup ))

print("Mean =", statistics.mean( tup ) )

Output:-

Enter a tuple :-(3,7,8,12,15,19,21,25)
Average = 13.75
Mean = 13.75
>>>

Enter a tuple :-(1,2,3,4,5,6,7,8,9,10)
Average = 5.5
Mean = 5.5
>>>

8 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post