You will write three small functions: one that finds a relative frequency in a list of results, one that simulates an event many times, and one that finds the band of the law of large numbers.
The idea. A relative frequency is the number of times an event happened divided by the number of tries. A computer can try an event of probability by checking random.random() < p, which is true about a share of the time. In about runs out of , the share lands within of .
Your tasks.
relative_frequency(results, target). Count how many items of the list equal target, and divide by the length of the list.simulate(p, n). Try the event n times and return the number of successes.band(p, n). Return the half-width .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…