Suspected Error in Test Module for Python Probability Calculator

The difference between your value and the expected is down to your draw() method. You shuffle and pop the array for each draw, which yields 0.252. When I did the project, I used random.choice() and got the expected probability (0.273). I tested the same method in your code and got the expected probability too. If you shuffle just once before the loop, it yields 0.261. Since each selection method uses a different number of random numbers in the same sequence, the selection algorithm will affect the calculated probability,

So, your code is correct, it’s just not in agreement with the test and its delta. It’s clear from these three methods of random choice that the delta is too small for the number of iterations. At 10,000 iterations with the set random seed, I get

./main.py 
# random.choice()
Probability: 0.269
# one shuffle
./main.py 
Probability: 0.2677
# shuffle every draw
./main.py 
Probability: 0.266

so the expected value could be set to 0.263 with the same delta and still work at 10,000 draws.

As far as your math goes, I concur that the actual value is 0.263, unless I miscounted, which is always possible.

1 Like