Probability Calculator in Python curriculum fails test with odd results

Okay,
I managed to get thru all the Scientific problems in the second level of Learn Python without posting a forum request, but I’m now stumped.

I will post my repl link below. I do add a number of optional print statements for my own diagnosis and I haven’t removed these yet, but they are commented out. And yes, I know there are extra self checking variables in my function that do not affect the outcome, but make the code slightly slower.

https://repl.it/@RaymondPotter/fcc-probability-calculator#test_module.py

Here is the issue.

The program (finally, sigh!) passes all the test conditions without crashing, except for the last one. Test three consistently flunks it in the second data set.

…F

FAIL: test_prob_experiment (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/fcc-probability-calculator/test_module.py”, line 26, in test_prob_experiment
self.assertAlmostEqual(actual, expected, delta = 0.01, msg = ‘Expected experiemnt method to return a different probability.’)
AssertionError: 0.122 != 0.272 within 0.01 delta (0.15000000000000002 difference) : Expected experiemnt method to return a different probability.


Ran 3 tests in 0.073s

FAILED (failures=1)"

Now I’m not sure if it’s how the random seed is generated but the result is always exactly 0.122. Since this is a probability experiment with many random draws, should 0.122 always be the exact same result? When I copy the function call data and run it in my local Py editor, it varies, although it is NEVER anywhere near 0.272

I am wondering if there is an error in the checking routine. It would not be the first that I’ve found. In the Budget Calculator check, one test tries to equate 54 with 854 and amazingly always fails. Note also that there is an obvious typo in the same check line, so the possibility exists of some error, but I do not see anyone else reporting it in the forum.

I am sure that the error is my own lack of knowledge, but if not, does anyone have an idea what the problem is?

Thank you for your help.

The test suite uses a fixed seed value.

I figured as much. So, any clues as to why it is flunking the test?

So . . . no suggestions ? ? ?

The test works.

You may want to look at using copy.deepcopy() instead of copy.copy(), at least for the hat object. Also, the line in your success test

if expected_list[color] == result_list[color]:

is too strict. If you want 2 green balls, and 2 or more green balls are drawn, then that should be a success.

Finally, since there is so much to debug, I would print the expected and result lists and whether the experiment was successful in your success test to make sure your code is correctly evaluating success and then work back from there.