Probability Calculator

Hi Guys. Can anyone explain to me why do I need to use the copy.deepcopy() when I’m using my class object inside the experiment function?

if I use the following, the code works:

for i in range(num_experiments):

    hat_copy = copy.deepcopy(hat)
    draw = hat_copy.draw(num_balls_drawn)

but, if I use the one bellow, the code starts to fail after a few iterations:

    draw = hat.draw(num_balls_drawn)

Each experiment is expected to start with the same balls in the hat. If hat will not be reset when starting single experiment, sooner or later hat will have at the start different number of balls and different balls will be drawn.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.