# Scientific Computing with Python Projects - Probability Calculator

Tell us what’s happening:
I need a little help with this project, my `experiment` function seems to be returning a lower than expected probability for the third test, I checked with debugger breakpoints, the logic of the inner loop seems fine, to me at least:

``````does_match = True
for color, count in expected_balls:
if draw.count(color) < count:
does_match = False
break
if does_match: num_matches += 1
``````

The function’s variables I believe are getting updated correctly, not sure how it could be skipping any matches. The test for `Hat(blue=3,red=2,green=6)` and `experiment(hat=hat, expected_balls={"blue":2,"green":1}, num_balls_drawn=4, num_experiments=1000)` should give a probability `0.272 ± 0.01` , except I’m getting a `0.14` , which is way off.

There’s also a lesser problem, the second test case, for some reason I’m getting [‘blue’, ‘blue’], without any ‘red’ being drawn. That’s not the case though if I test it locally and repeat the proces for 50 times

``````for i in range(50):
hat = prob_calculator.Hat(red=5,blue=2)
print(hat.draw(2))
``````

Nearly four-fifths of the output shows at least one red, if not both red. If I change the seed to 10,000 in `test_module.py` on replit though, the error disappears.

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36`

Challenge: Scientific Computing with Python Projects - Probability Calculator

Both issues might be caused by the same thing. Take a closer look at the `draw` method, try making sure everything is in order there.