Python Programming · High School (11–12) · 3 courses, 23 worked problems, 40 practice questions
Some events depend on chance, such as a coin toss, the decay of an atom or the path of a molecule in a gas. Python's random module gives random numbers, and NumPy can give millions at once. A simulation repeats a chance event many times and counts the results. With enough trials, the fraction of heads comes close to one half. This is the idea behind the Monte Carlo method. It can estimate by scattering random points in a square, model radioactive decay or follow a random walk. Setting a seed makes a simulation repeat exactly.
Choose an answer, then check it. Each one shows a full explanation.
A loop follows a culture of Amoeba through four divisions. What does it print? N = 70; for i in range(4):; N = 2 * N; print(N)
A culture of 160 cells doubles every 35 min. What does this print? print(160 * 2 ** (105 / 35))
A culture doubles every min. Which expression gives its growth rate per minute, for ?
Each one has a hint, the key idea and a full worked solution.
Counts that grow exponentially are plotted with plt.yscale("log"). What shape do they make?
Counting times for a growth experiment, in minutes. What does this print? import numpy as np; t = np.arange(0, 61, 15); print(len(t), t[-1])
In logistic growth, how does the population grow while is very small compared with ?
One logistic step for a pond of algae. What does it print? r, K, N, dt = 0.25, 1500, 375, 2; N = N + r * N * (1 - N / K) * dt; print(N)
Yeast in a brewing vat stops multiplying once it holds cells. How many cells does the vat hold when the count rises most quickly?
A fit to three counts. What does it print? import numpy as np; t = np.array([0, 10, 20]); N = np.array([90, 180, 360]); slope, c = np.polyfit(t, np.log(N), 1); print(round(np.log(2) / slope, 1))
What does curve_fit(model, t, N, p0=[0.25, 950]) return first?