Mean, Medium, Mode

Mean (μ\mu)

The average of all the integers in a set of values. Here is the basic formula for calculating the mean of a set of nn values: μ=i=1nxin\mu = \frac{\sum_{i=1}^n x_i}{n}, where xxis the ithi^{th}element of the set.

The midpoint value of a data set for which an equal number of samples are less than and greater than the value. For an odd sample size, this is the middle element of the sorted sample; for an even sample size, this is the average of the 22 middle elements of the sorted sample.

The element(s) that occur most frequently in a data set. For the set 1,1,1,2,2,3,4,4{1, 1, 1, 2, 2, 3, 4, 4}, the mode is 11 because the number 11 appears three times in the set and every other number in the set has a frequency <3< 3. In contrast, the set {1,2,3,4}\{1, 2, 3, 4\} is multimodal because no number in the set appears more than 11 time, so every number in the set is a valid mode.

These are important terms to understand when formatting your output:

  • Precision refers to the number of significant digits in a number. For example, the numbers 123.45123.45 and 0.0123450.012345 both have a precision of 55.

  • Scale refers to the number of significant digits to the right of the decimal point. For example, the number 123.45123.45 has a scale of 22 decimal places. This term is sometimes misrepresented as precision in documentation.

num = int(input())
values = list(map(int, input().split()))

mean = sum(values)/num
print(mean)

values.sort()
if num % 2 == 0:
    v1 = values[int(num/2)-1]
    v2 = values[int(num/2)]
    median = (v1+v2)/2
else:
    c = floor(num % 2) + 1
    median = values[c]
print(median)

mode = max(values, key=lambda n: values.count(n))
print(mode)

Last updated