# Probability Calculator

Hello everyone,

I’ve done this project except for the 3rd test.
every time I run the test, the result is 0.252, always the same with multiple tries.
but if I use \$ python3 prob_calculator.py . it works well.

This is my code: https://replit.com/@hudir2/boilerplate-probability-calculator

Can someone help me?
Thanks!

The tests use a seed for the random number generator that you are not using in your code so that the results are repeatable, hence the correct answer is 0.272. Since your probability is low you should begin by logging the draws in your experiment along with their success or failure and look for ones that are misclassified, especially ones that are marked failures that should be successes.

Thanks a lot, jeremy.
I add seed(95) to my code and get 0.262 this time when using \$ python3 prob_calculator.py.
And like you said I logged out all draws which failed like this:
lack 1 blue, get {‘green’: 2, ‘blue’: 1, ‘red’: 1}
lack 1 blue, get {‘green’: 2, ‘red’: 1, ‘blue’: 1}
lack 1 green, get {‘blue’: 3, ‘red’: 1}
lack 1 blue, get {‘blue’: 1, ‘green’: 3}
lack 1 blue, get {‘green’: 2, ‘red’: 1, ‘blue’: 1}
lack 1 blue, get {‘green’: 3, ‘blue’: 1}
and checked them but can not find the reason

If it’s not your experiment classifier, then it has to be your draw method. Since you’re doing everything manually, you really need to make sure your indices are correct as you’re drawing randomly.

I logged also random index and what was left in contents, and everything seems good. I also checked the draw method again with only three balls like Hat(blue=1,red=1,green=1,gray=1), and it works normally.
the random index in the range from 0 - 10 for 11 balls(blue=3,red=2,green=6)
Here are some logged out data:

random 6 random 9 random 0 random 3 left {‘blue’: 2, ‘red’: 1, ‘green’: 4} lack 1 blue, get {‘green’: 2, ‘blue’: 1, ‘red’: 1}
random 3 random 6 random 7 random 3 left {‘blue’: 3, ‘green’: 4} lack 2 blue, get {‘red’: 2, ‘green’: 2}
random 10 random 5 random 4 random 7 left {‘blue’: 3, ‘red’: 1, ‘green’: 3} lack 2 blue, get {‘green’: 3, ‘red’: 1}
random 8 random 9 random 3 random 1 left {‘blue’: 2, ‘red’: 1, ‘green’: 4} lack 1 blue, get {‘green’: 2, ‘red’: 1, ‘blue’: 1}
random 10 random 3 random 3 random 3 left {‘blue’: 3, ‘green’: 4} lack 2 blue, get {‘green’: 2, ‘red’: 2}
random 2 random 1 random 7 random 2 left {‘blue’: 1, ‘red’: 1, ‘green’: 5} succsee {‘blue’: 2, ‘green’: 1, ‘red’: 1}
random 9 random 8 random 7 random 1 left {‘blue’: 2, ‘red’: 2, ‘green’: 3} lack 1 blue, get {‘green’: 3, ‘blue’: 1}
random 4 random 9 random 0 random 6 left {‘blue’: 2, ‘red’: 1, ‘green’: 4} lack 1 blue, get {‘red’: 1, ‘green’: 2, ‘blue’: 1}
random 5 random 5 random 6 random 5 left {‘blue’: 3, ‘red’: 2, ‘green’: 2} lack 2 blue, get {‘green’: 4}

The hint about checking your draw method was because I swapped your draw method for a different one and all the tests passed. The problem is in your draw method.

I changed draw method and get it passed all tests.
although I think my way is closer to “draw a ball from a hat” but not “draw the first ball of that color from a hat”. But anyway, Thank you a lot jeremy for answering and helping! Have a nice weekend!

I just swapped your draw method to use `random.choice()` and the list `remove()` method instead of doing the steps manually. With that change, you really are selecting at random. Manual random selections from a list are prone to lower index bias and index problems like never selecting the last element. I didn’t debug the original, but that is like the problem.

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