Sum up a column of data: its mean, median and (population) standard deviation.
Input
The first line has n (1 ≤ n ≤ 1000). The second line has n numbers (integers or decimals).
Output
Three lines: mean M, median D and std S, each with 2 decimal places. The standard deviation divides by n, not n − 1.
Examples
Example 1 · Input
8 72 85 64 90 78 0 81 69
Expected output
mean 67.38 median 75.00 std 26.68
Example 2 · Input
3 2 9 4
Expected output
mean 5.00 median 4.00 std 2.94
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
The median is the middle value after sorting; with an even count, the mean of the two middle values.
Hint 2
Variance: the mean of (x − mean)². The standard deviation is its square root.
Hint 3
Print with f"{value:.2f}".
Solution
Show one correct solution (try it yourself first)
n = int(input())
xs = [float(x) for x in input().split()]
mean = sum(xs) / n
s = sorted(xs)
median = s[n // 2] if n % 2 == 1 else (s[n // 2 - 1] + s[n // 2]) / 2
std = (sum((x - mean) ** 2 for x in xs) / n) ** 0.5
print(f"mean {mean:.2f}")
print(f"median {median:.2f}")
print(f"std {std:.2f}")