You will write three functions that find probabilities for draws from a group, using math.comb: the number of selections, the chance of exactly special objects, and the chance of at least . The checker compares them with a count of every selection in a small case.
The idea. A group has special objects of one kind and others of another. A selection of drawn objects has exactly k special ones in ways. All selections number .
Your tasks.
selections(n, r). Return the number of ways to choose r objects from n.chance_exactly(special, others, drawn, k). Return the probability of exactly k special objects as a Fraction.chance_at_least(special, others, drawn, k). Add the chances of k, k + 1, and so on.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…