Chapter 1 · Section 6 practice
SciPy Probability
Work from question 1 to 10. Edit your Python box, click Run Code, review the result, then click Submit attempt. Reference answers unlock after all ten attempts are submitted. This records completion, not correctness. Each box runs independently. Progress is saved in this browser.
1. Probability at the mean
Warm-up. Print the probability of a waiting time at most 8 minutes for normal mean 8, sd 2, to four decimals.
Write your answer, then run it.
2. Probability below a limit
Warm-up. Calculate P(X ≤ 10) for normal mean 8, sd 2. Print four decimals.
Write your answer, then run it.
3. Find the median cutoff
Warm-up. Calculate the 50th percentile for normal mean 8, sd 2. Print two decimals.
Write your answer, then run it.
4. Calculate the upper tail
Build your skills. Print P(X > 10) for normal mean 8, sd 2, as a percentage with one decimal.
Write your answer, then run it.
5. Calculate an interval
Build your skills. Print P(6 ≤ X ≤ 10) for normal mean 8, sd 2, as a percentage with one decimal.
Write your answer, then run it.
6. Find a service cutoff
Build your skills. For normal mean 28, sd 6, print the 95th percentile to two decimals with units. Explain its meaning in a comment.
Write your answer, then run it.
7. Check inverse functions
Build your skills. Find the 90th percentile for normal mean 28, sd 6; pass it into CDF. Print cutoff to two decimals and checked probability to four.
Write your answer, then run it.
8. Compare variability
Challenge. Compare P(X > 40) for normal models with the same mean 28 but sd 6 and sd 10. Print each percentage to two decimals and explain the result.
Write your answer, then run it.
9. Compare observations and a model
Challenge. Print the observed proportion of times above 40 and the modeled probability for mean 28, sd 6. Use four decimals and explain why they differ.
Write your answer, then run it.
10. Assess a proposed promise
Challenge. For normal mean 28, sd 6, calculate P(X ≤ 35) and the cutoff needed for 95% coverage. Print the first as a two-decimal percentage and the second to two decimals. Explain whether a 35-minute promise meets 95% under the model.
Write your answer, then run it.
Reference answers are locked until all 10 attempts are submitted.
1. Probability at the mean
from scipy import stats
print(f"{stats.norm.cdf(8, loc=8, scale=2):.4f}")Expected output
0.5000Half the symmetric normal model lies below its mean.
2. Probability below a limit
from scipy import stats
print(f"{stats.norm.cdf(10, loc=8, scale=2):.4f}")Expected output
0.8413CDF maps the cutoff to a probability.
3. Find the median cutoff
from scipy import stats
print(f"{stats.norm.ppf(0.50, loc=8, scale=2):.2f}")Expected output
8.00The normal median equals its mean.
4. Calculate the upper tail
from scipy import stats
p = 1 - stats.norm.cdf(10, loc=8, scale=2)
print(f"{p:.1%}")Expected output
15.9%Subtract cumulative probability from one.
5. Calculate an interval
from scipy import stats
p = stats.norm.cdf(10, loc=8, scale=2) - stats.norm.cdf(6, loc=8, scale=2)
print(f"{p:.1%}")Expected output
68.3%Subtract the two cumulative probabilities.
6. Find a service cutoff
from scipy import stats
cutoff = stats.norm.ppf(0.95, loc=28, scale=6)
print(f"{cutoff:.2f} minutes")
# Under the model, 95% of times are at or below this cutoff.Expected output
37.87 minutesThe probability is 0.95; the output is a value in minutes.
7. Check inverse functions
from scipy import stats
cutoff = stats.norm.ppf(0.90, loc=28, scale=6)
p = stats.norm.cdf(cutoff, loc=28, scale=6)
print(f"{cutoff:.2f}")
print(f"{p:.4f}")Expected output
35.69
0.9000CDF and PPF reverse each other for probabilities strictly between zero and one.
8. Compare variability
from scipy import stats
for sd in [6, 10]:
p = 1 - stats.norm.cdf(40, loc=28, scale=sd)
print(f"{p:.2%}")
# At this cutoff above the mean, more spread increases the upper-tail probability.Expected output
2.28%
11.51%The same mean does not imply the same probability of missing this service target.
9. Compare observations and a model
import pandas as pd
from scipy import stats
times = pd.Series([20, 25, 28, 32, 45])
print(f"{(times > 40).mean():.4f}")
print(f"{1 - stats.norm.cdf(40, loc=28, scale=6):.4f}")
# One describes five observed values; the other uses a specified normal model.Expected output
0.2000
0.0228Different information sources can produce different probabilities.
10. Assess a proposed promise
from scipy import stats
coverage = stats.norm.cdf(35, loc=28, scale=6)
cutoff = stats.norm.ppf(0.95, loc=28, scale=6)
print(f"{coverage:.2%}")
print(f"{cutoff:.2f} minutes")
# 35 minutes covers less than 95% under this model.Expected output
87.83%
37.87 minutesThe calculation is conditional on the normal model, not a guarantee for every delivery.