Session Ready
Exercise

Probability example

In this exercise, we will review the difference between sampling with and without replacement. We will calculate the probability of an event using simulation, but vary our sampling method to see how it impacts probability.

Consider a bowl filled with colored candies - three blue, two green, and five yellow. Draw three candies, one at a time, with replacement and without replacement. You want to calculate the probability that all three candies are yellow.

Instructions
100 XP
  • Set up your bowl as a list having three blue 'b', two green 'g' and five yellow 'y' candies.
  • Draw a sample of three candies with replacement (sample_rep) and without replacement (sample_no_rep).
  • For the sample with replacement, if there are no 'b' or 'g' candies in sample_rep, increment success_rep. Similarly, incrementsuccess_no_rep when there are no 'b' or 'g' candies in sample_no_rep.
  • Calculate the respective probabilities as successes divided by number of iterations.