14
Question Question 12
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.
Solution
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