So close yet so confused. Probability Calculator

Hi,

I can either pass the probability_experiment test or the hat_draw test but not both. The error that I’m getting is quite straight forward to fix, but I can’t fix it without messing up the experiment.

The error I’m getting is:
“AssertionError: 7 != 5 : Expected hat draw to reduce number of items in contents.”

I’ve tried changing my code so that the draw function “takes balls” out of the contents of the hat with each iteration of the draw, but I can’t seem to get the hat to return to its original value after each time the draw function is used. This means that the probability calculation is messed up.

The way I have tried to fix it it is by recording the self.contents in a variable at the start of the draw function, then I try to reassign that to self.contents after the draw has been performed but before the return statement, but it doesn’t seem to work.

I’m finding it very hard to explain but perhaps looking at my code will make it clearer. Thanks in advance…

I think you are supposed to use the “copy” method provided by the innitial imports.
Personally I just read from someone creating a method to refill the hat with the original balls at the end of every draw in the experiment and that’s quite straightforward to implement.

Thanks for that - you were absolutely right. I was using the copy method in the draw function whereas I should have been using it in the experiment function. Passed the test in the end with your help and another hour of tweaking my code.

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