Chapter 1 quiz
Ten questions to bring the chapter together.
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.
Question 1
This cell imports math as m. Complete a valid call to find the square root of 144. In a comment, explain why sqrt(144) alone is not defined by this import.
Write your answer, then run it.
Question 2
From [42, 58, 28, 65], produce a new list containing a HK$5 discount only on prices at least 50. Print it and comment whether the original list changes.
Write your answer, then run it.
Question 3
Predict then print the two results below. Explain their different lengths in a comment.
Write your answer, then run it.
Question 4
Calculate counts [85, 110, 140] × bills [42, 58, 28]. Create a Series labelled Wonton, Char Siu, Milk Tea. Print the total and the label with the largest value.
Write your answer, then run it.
Question 5
Two classmates obtain different standard deviations from these same observations. Print both library defaults to three decimals, then change the NumPy call to match pandas. Explain in a comment.
Write your answer, then run it.
Question 6
Print the first value by position and the value labelled 10 from this Series. Explain why a label is not automatically its position.
Write your answer, then run it.
Question 7
Choose a chart for unordered dish revenues [3570, 6380, 3920]. Draw it with labels and units, then print the highest-revenue dish. State in a comment one reason this does not establish which dish is most profitable.
Write your answer, then run it.
Question 8
Assume normal delivery times with mean 28 and sd 6 minutes. Calculate the chance of exceeding 40 minutes. Print a two-decimal percentage and state the assumption in a comment.
Write your answer, then run it.
Question 9
For normal mean 28 and sd 6, find the cutoff containing 95% of times below it, then verify its cumulative probability. Print cutoff to two decimals with units, then probability to four decimals.
Write your answer, then run it.
Question 10
For observed times [20, 25, 28, 32, 45], print (1) the proportion above 40, (2) the sample 95th percentile, and (3) the normal-model 95th percentile for mean 28 and sd 6. Use two decimals. Explain why the last two need not match and why neither guarantees every delivery.
Write your answer, then run it.
Reference answers are locked until all 10 attempts are submitted.
Question 1
import math as m
print(m.sqrt(144))
# The statement introduces m; it does not introduce sqrt directly.Expected output
12.0Calls must match the imported name.
Question 2
prices = [42, 58, 28, 65]
result = [p - 5 for p in prices if p >= 50]
print(result)
# The comprehension creates a new list; prices is unchanged.Expected output
[53, 60]Filtering and transformation can be combined.
Question 3
import numpy as np
values = [10, 20]
print(values * 2)
print(np.array(values) * 2)
# The list repeats its two items; the array doubles two values.Expected output
[10, 20, 10, 20]
[20 40]The operator’s behavior depends on the object type.
Question 4
import numpy as np
import pandas as pd
counts = np.array([85, 110, 140])
bills = np.array([42, 58, 28])
revenue = pd.Series(counts * bills, index=["Wonton", "Char Siu", "Milk Tea"])
print(revenue.sum())
print(revenue.idxmax())Expected output
13870
Char SiuArrays calculate values; Series labels identify which dish has the maximum.
Question 5
import numpy as np
import pandas as pd
values = [100, 102, 98, 105, 101]
print(f"{pd.Series(values).std():.3f}")
print(f"{np.std(values):.3f}")
print(f"{np.std(values, ddof=1):.3f}")
# pandas defaults to ddof=1; NumPy defaults to ddof=0.Expected output
2.588
2.315
2.588Matching the statistical convention resolves the difference.
Question 6
import pandas as pd
s = pd.Series([100, 200, 300], index=[30, 10, 20])
print(s.iloc[0])
print(s.loc[10])
# The first position has label 30, while label 10 is second.Expected output
100
200Use explicit positional and label-based selectors.
Question 7
import pandas as pd
import matplotlib.pyplot as plt
revenue = pd.Series([3570, 6380, 3920], index=["Wonton", "Char Siu", "Milk Tea"])
revenue.plot(kind="bar", figsize=(6, 3), rot=0)
plt.title("Revenue by dish")
plt.xlabel("Dish")
plt.ylabel("Revenue (HK$/day)")
plt.tight_layout()
plt.show()
print(revenue.idxmax())
# Costs are absent; revenue is not profit.Expected output
Char SiuThe chart compares categories. It cannot rank profitability without costs.
Question 8
from scipy import stats
p = 1 - stats.norm.cdf(40, loc=28, scale=6)
print(f"{p:.2%}")
# The normal distribution and these parameters are assumed to apply.Expected output
2.28%The complement of CDF gives the upper-tail probability.
Question 9
from scipy import stats
cutoff = stats.norm.ppf(0.95, loc=28, scale=6)
print(f"{cutoff:.2f} minutes")
print(f"{stats.norm.cdf(cutoff, loc=28, scale=6):.4f}")Expected output
37.87 minutes
0.9500A probability-to-cutoff calculation is checked by reversing it.
Question 10
import pandas as pd
from scipy import stats
times = pd.Series([20, 25, 28, 32, 45])
print(f"{(times > 40).mean():.2f}")
print(f"{times.quantile(0.95):.2f}")
print(f"{stats.norm.ppf(0.95, loc=28, scale=6):.2f}")
# The sample and the assumed model are different sources of information.
# A 95th percentile leaves a tail; it is not a guarantee for every order.Expected output
0.20
42.40
37.87Observed proportions, sample quantiles, and model percentiles have different interpretations.