You will test the quick rule for the margin of luck. Your program runs many fair polls and counts how many land within the margin of the truth.
The idea. The quick rule says that about 95 fair polls in 100 land within percentage points of the true percentage. Each person in a poll says yes with the chance , the true share.
Your tasks.
margin(n). Return the quick rule's margin in percentage points.poll(n, p). Ask n people at random, where each says yes with the chance p, and return the percentage who say yes.share_within(n, p, polls). Run polls polls and return the fraction of them that land within the margin of 100 * p.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…