Computer Science
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.
Python
Python Tuples
13 Likes
Answer
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
Answered By
5 Likes
Related Questions
Write a program that inputs two tuples seq_a and seq_b and prints True if every element in seq_a is also an element of seq_b, else prints False.
Computing Mean. Computing the mean of values stored in a tuple is relatively simple. The mean is the sum of the values divided by the number of values in the tuple. That is,
Write a program that calculates and displays the mean of a tuple with numeric elements.
Write a program to check the mode of a tuple is actually an element with maximum occurrences.
Mean of means. Given a nested tuple tup1 = ( (1, 2), (3, 4.15, 5.15), ( 7, 8, 12, 15)). Write a program that displays the means of individual elements of tuple tup1 and then displays the mean of these computed means. That is for above tuple, it should display as :
Mean element 1 : 1. 5 ;
Mean element 2 : 4.1 ;
Mean element 3 : 10. 5 ;
Mean of means 5. 366666