A survey asked "How many hours do you usually sleep?". Turn the answers into a short summary.
What to build
A program that summarises numeric survey answers.
Requirements
- Print
answers: N,min: Xandmax: X(one decimal),mean: X(two decimals) andunder 7 hours: K (P%), where P is the percentage of answers below 7, to one decimal.
Input
Line 1: n. Then n lines, each a number of hours (with at most one decimal place).
Output
Five lines.
Constraints
1 ≤ n ≤ 1000; 0 ≤ hours ≤ 24.
Example
Input:
5
6
7.5
8
5.5
7
Output:
answers: 5
min: 5.5
max: 8.0
mean: 6.80
under 7 hours: 2 (40.0%)
Why it works
A handful of numbers (count, range, mean and the share below a threshold) describes a whole column well enough to see whether something stands out, which is the first thing to do with any survey.
Examples
Example 1 · Input
5 6 7.5 8 5.5 7
Expected output
answers: 5 min: 5.5 max: 8.0 mean: 6.80 under 7 hours: 2 (40.0%)
Example 2 · Input
3 7 7 7
Expected output
answers: 3 min: 7.0 max: 7.0 mean: 7.00 under 7 hours: 0 (0.0%)
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Read every answer into a list of floats first; then min, max and sum do most of the work.
Hint 2
The share is 100 × count ÷ n, rounded to one decimal.
Solution
Show one correct solution (try it yourself first)
n = int(input())
hours = [float(input()) for _ in range(n)]
short = sum(1 for h in hours if h < 7)
print("answers:", n)
print(f"min: {min(hours):.1f}")
print(f"max: {max(hours):.1f}")
print(f"mean: {sum(hours) / n:.2f}")
print(f"under 7 hours: {short} ({100 * short / n:.1f}%)")