Another Randomizer doesn't agree with the test -Scientific Computing with Python Projects - Probability Calculator

Hello everyone!
Well I am stuck with this exercise. Everything seems to be working perfectly, balls are returned properly, successes are counted properly, there seems to be a semi random choice of balls from the original hat, but the probability my program returns is not the same as the expected.

Could it be that the randomizer works wrong or that I have missed the way to choose balls?

Thank you so much in advance.

This is my replit link:
prob_calculator.py - boilerplate-probability-calculator - Replit

Your browser information:

User Agent is: Microsoft Edge
Version 99.0.1150.36 (Official build) (64-bit)
but I have also tried Brave and Chrome.

Challenge: Scientific Computing with Python Projects - Probability Calculator

Link to the challenge:

There’s really nothing random about this project, since the random number generator is seeded to produce the same random numbers on each run of the tests. So any randomness in the results is generated by your code.

Your probability is too high, so that means you are accepting too many draws as good when they are bad. I modified part of your good/bad test to log the results like

        if found_balls == True:
            successes += 1
            print(f"good:  e: {expected_balls} d: {draw}")
        else:
            print(f"bad:  e: {expected_balls} d: {draw}")

and got output like

good:  e: {'blue': 2, 'green': 1} d: ['green', 'green', 'green', 'blue']
good:  e: {'blue': 2, 'green': 1} d: ['green', 'blue', 'red', 'red']
good:  e: {'blue': 2, 'green': 1} d: ['blue', 'green', 'green', 'red']
good:  e: {'blue': 2, 'green': 1} d: ['green', 'blue', 'green', 'red']
good:  e: {'blue': 2, 'green': 1} d: ['green', 'green', 'blue', 'green']
good:  e: {'blue': 2, 'green': 1} d: ['blue', 'green', 'green', 'green']
good:  e: {'blue': 2, 'green': 1} d: ['green', 'green', 'red', 'blue']
good:  e: {'blue': 2, 'green': 1} d: ['blue', 'green', 'green', 'green']
good:  e: {'blue': 2, 'green': 1} d: ['red', 'blue', 'green', 'green']

which were just the wrong results from the first 10 results. So, you’ll need to diagnose the problem in your code that’s deciding if a draw is good or bad, at least, as the problem is either there (most likely) or further back in your Hat class.

1 Like

Thank you for your advice, I will try harder on it. I think I see that it checks if there is a color, but it doesn’t properly calculate how many balls of the color there are.

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