You will write the multiplication rule for any number of independent events, the rule for at least one, and a simulation that checks the rule for a coin and a die.
The idea. For independent events, the chance that all of them happen is the product of their chances. The chance that at least one happens is minus the chance that none happens. A simulation can count how often a head and a six come together.
Your tasks.
p_all(chances). Multiply all the chances in the list. An empty list gives .p_at_least_one(chances). Return minus the product of the chances that each event fails.share_head_six(n). Toss a coin with random.choice("HT") and roll a die with random.randint(1, 6), n times. Return the share of tries with a head and a six.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…