You will test a coin both ways: by simulation and by exact counting.
The idea. Under the null idea, the coin is fair. The p-value is the chance that a fair coin gives at least as many heads as the real one.
Your tasks.
heads_in(n). Toss a fair coin n times with random.random() < 0.5 and return the number of heads.p_value_sim(observed, n, sets). Return the share of sets simulated sets with at least observed heads.p_value_exact(observed, n). Return times the sum of comb(n, h) for h from observed to n.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…