Help Wanted in Probability Calculator Challenge

Tell us what’s happening:
Hello, I am having an issue with my Probability Calculator when writing the experiment function. For each num_experiments I am making a deep copy of the hat and calling the draw method with num_balls_drawn. This results in an “IndexError: list index out of range”… I am quite confused because the draw method seems to work otherwise…

Any help will be greatly appreciated. Thank you!

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36.

Challenge: Probability Calculator

Link to the challenge:

Take a closer look at what happens inside of the draw method.

For n_draws times:

  • drawn index of the ball is picked
  • ball matching one with on the drawn index is removed from balls_left list, keep in mind that remove method removes the first matching occurrence from the list.
  • ball matching one on the drawn index is added to the balls_drawn list

Do you see what is not right here? Try to go step-by-step through this, you might add temporally print calls to see what is going on in the affected variables.

Thank you for your help! As you suggested the temporary print calls helped me figure out that the stopping point for random.randint(start, stop) had to be reduced by 1.