You will write a small simulation toolkit. It has a function that estimates a probability. It has one experiment, two friends who may meet. It has a test of whether an estimate is within the usual error of the exact value.
The idea. Run an experiment many times and count the successes. The fraction is an estimate. With trials runs and an exact probability p, the usual error is about . A result is close enough when it lies within three times that error.
Your tasks.
estimate(experiment, trials, seed). Make rng = random.Random(seed), run experiment(rng) trials times and return the fraction of runs that gave True.two_friends(rng). Draw two arrival times with rng.uniform(0, 60) and return True if they differ by at most minutes.close_enough(est, exact, trials). Return True if est is within three usual errors of exact.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…