You will write three small functions that list sample spaces: the results of several tosses, the ordered draws from a bag without replacement, and the draws taken together. The checker counts them for a coin and for a bag of letters.
The idea. A sample space is a list of outcomes, so the computer can build it and count it. itertools.product gives every string of tosses. itertools.permutations gives ordered draws with no repeats. itertools.combinations gives draws with the order ignored.
Your tasks.
tosses(n). Return a list of strings such as "HTH", one for each outcome of n tosses.ordered_draws(balls, r). Return the list of ordered draws of r balls without replacement.together_draws(balls, r). Return the list of draws of r balls taken together.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…