Build a Probability Calculator Project - Build a Probability Calculator Project

I had the issue that the self.contents was getting empty in just a few iterations inside the experiment loop. So I made this workaround:

        new_hat = copy.deepcopy(hat)
        drawn_balls = hat.draw(num_balls_drawn)
        hat = new_hat

I am getting the same range percentage, so Idk what is happening now

Edit: nvm, I think I found the issue, brb
Edit 2: nope, still lost

self.contents gets empty because balls are kept drawing for the same hat between each experiment. Say, 2 balls are drawn from a hat of 10 balls, after the drawing the hat has 8 balls remain. If the hat is not renewal to 10 balls before the next experiment, the ball will keep decreasing and empty soon.

I believe there is a problem using “shuffle” to take a random ball

https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-probability-calculator/682836

I think you were on the right track using random.randrange instead

More about this here:
https://forum.freecodecamp.org/t/suspected-error-in-test-module-for-python-probability-calculator/437633/2

The “new_hat” copies the filled “hat” before getting drawn and then I restock the “hat” with “new_hat”. I should have named it “filled_hat” instead =b

1 Like

Yep, random,randrange and random.shuffle return a different probability… I passed the tests.

I don’t know if this is the correct place to give feedback, but I would appreciate that the instructions are more clear with the draw method, like improve the wording or provide an example; second, if they are going to use such small delta, then provide the specific random method to use =T

Thank you pkdvalis and SzeYeung1

2 Likes

I think this is a good actionable fix. It’s come up a number of times and is never clearly explained.

If you have an idea to improve the wording can you provide an example?

1 Like

"The Hat class should have a draw method that accepts an argument indicating the number of balls to draw from the hat. The method will draw the balls randomly from self.contents and move them to a list of drawn balls. The balls should not go back into the hat during the draw, that means the hat will have a reduced number of balls each time the draw method is called.

If the number of balls to draw exceeds or is the same as the available quantity, that means you need to draw all the balls and leave the hat empty.

In addition, the hat will need to be refilled for every experiment to avoid the scenario of running out of balls from consecutive draws."