# Probability Calculator - Failing last part of final test

Tell us what’s happening:
I’ve poured over each part of the code multiple times, verified the draw and matches manually, and I can’t figure out why the final part of the final test is failing. I’m getting .64 probability when the test wants 1.0. All other tests are passing.

``````======================================================================
FAIL: test_prob_experiment (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-probability-calculator/test_module.py", line 32, in test_prob_experiment
self.assertAlmostEqual(actual, expected, delta = 0.01, msg = 'Expected experiment method to return a different probability.')
AssertionError: 0.64 != 1.0 within 0.01 delta (0.36 difference) : Expected experiment method to return a different probability.

----------------------------------------------------------------------
Ran 3 tests in 0.182s

FAILED (failures=1)
``````

Challenge: Scientific Computing with Python Projects - Probability Calculator

That’s the case with number of balls to be drawn higher than the number of balls in the hat. How are you handling situation when number of balls to draw is higher than the number of balls in hat? Also each experiment is supposed to start with the same, initial, balls in the hat.

At the start of the draw I am resetting the contents variable. If the number of balls to draw is higher than the contents, I reset the contents back to the base value. I made a clean copy in the init to reinitialize from.

``````    def draw(self, num_balls):
self.contents = copy.deepcopy(self.copy)

while i != num_balls:
if num_balls > len(self.contents):
self.contents = copy.deepcopy(self.copy)
``````

Lets say `10` balls are to be drawn and there are `5` balls in hat. How many times hat will be refilled?

Oh, I see now. The hat is initialized with 19 balls but it wants us to pull 20. My code for evaluating whether or not to put balls back in was flawed so it kept putting balls back when it shouldn’t have. Thanks for helping me narrow down where to look!

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