Computer Science
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.
Python
Python Tuples
4 Likes
Answer
tup = eval(input ("Enter the numeric tuple: "))
total = sum(tup)
tup_length = len(tup)
mean = total / tup_length
print("Mean of tuple:", mean)
Output
Enter the numeric tuple: 2,4,8,10
Mean of tuple: 6.0
Answered By
2 Likes
Related Questions
Given a tuple pairs = ((2, 5), (4, 2), (9, 8), (12, 10)), count the number of pairs (a, b) such that both a and b are even.
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.
Write a program to check the mode of a tuple is actually an element with maximum occurrences.
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.