KnowledgeBoat Logo

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,

xˉ=xN;x=the sum of x,N=number of elements\bar{x} = \dfrac{\sum x}{N} ; \\[1em] \sum x = \text{the sum of } x, \\[1em] N = \text{number of elements}

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