Turn the 68-95-99.7 rule into actual ranges of values for a normal distribution.
What to build
A program that prints the ranges holding about 68%, 95% and 99.7% of values.
Requirements
- Print
1 SD: A to B,2 SD: C to Dand3 SD: E to F, every number to 2 decimal places.
Input
One line: the mean and the standard deviation.
Output
Three lines.
Constraints
The standard deviation is more than 0; |mean| ≤ 10⁶.
Example
Input:
100 15
Output:
1 SD: 85.00 to 115.00
2 SD: 70.00 to 130.00
3 SD: 55.00 to 145.00
Why it works
The rule is stated in standard deviations from the mean, so each range is the mean plus and minus k standard deviations.
Examples
Example 1 · Input
100 15
Expected output
1 SD: 85.00 to 115.00 2 SD: 70.00 to 130.00 3 SD: 55.00 to 145.00
Example 2 · Input
0 1
Expected output
1 SD: -1.00 to 1.00 2 SD: -2.00 to 2.00 3 SD: -3.00 to 3.00
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
The k-SD range runs from mean − k × sd to mean + k × sd.
Hint 2
Use an f-string with :.2f for both ends.
Solution
Show one correct solution (try it yourself first)
mean, sd = map(float, input().split())
for k in (1, 2, 3):
print(f"{k} SD: {mean - k * sd:.2f} to {mean + k * sd:.2f}")