Python Probability Testing Type Issue

I’m having an error in my python probability calculator with the testing suite. I think my program is working properly, but I get the following error from the tests:

ERROR: test_prob_experiment (test_module.UnitTests)
Traceback (most recent call last):
  File "/home/runner/fcc-probability-calculator-1/", line 31, in test_prob_experiment
    self.assertAlmostEqual(actual, expected, delta = 0.01, msg = 'Expected experiment method to return a different probability.')
  File "/usr/lib/python3.8/unittest/", line 943, in assertAlmostEqual
    diff = abs(first - second)
TypeError: unsupported operand type(s) for -: 'str' and 'float'

Ran 3 tests in 0.186s

FAILED (errors=1)

Here’s my for referencing what’s going on, I cannot explain it any further really, I tested the types of my outputs, the probability calculator is returning a float, which should be all the test is evaluating?

My current solution

Notice the issue is with case when number of balls to draw is higher than the number of balls in hat. Take a closer look at the specification, in such case, after drawing all balls from the hat, they are supposed to be returned to the hat for further drawing.

Ohhhh you are right! It was that edge case that I added for no reason lol :). All good, it works now! Question: did you notice that right away when you were looking at my solution, or you were able to somehow tell from the error message? Thank you!

Well it was both. Error was saying about str - TypeError: unsupported operand type(s) for -: 'str' and 'float', so it then required looking in code where function might have been returning str and why.

1 Like

Thank you! I will save myself a lot of time as I get better as assessing errors!