Problems with python probability calculator

Hi, I think I need help with the assignment “Probability Calculator”.
I cannot understand why it fails the test_prob_experiment, but I’m pretty sure it’s a problem of random seeding or something like that, becaus when I pool the dictionary generated by my object Hat it seems to pool always the same values.
Please, help me!
Thanks in advance!
I’m linking my repl My Repl

your repl link doesn’t work. could you link it again, thanks

Hi, I have now had a look at your code and i found some things that are causing it to break. The first thing is that your cmp function incorrectly returns the difference.

def cmp(expected, extracted):
    result = extracted - expected
    return result if result > -1 else -1

This will fix that. This finds the difference between expected ball count, and what has been drawn from the hat. It returns -1 if there diference is greater then -1.
(Although your current implimentation of checking works, its not great and is very unclear. I would change it to a True/ False list and then instead of checking if it contains any -1, you could just use the any() function. )

The next problem lies in how you draw from the hat(Hat.draw). It has a bias. Instead of using the random.sample, try and change it to the following:

start with a empty list. We shall call this removed. It will represent all the balls removed from the hat(aka drawn)

def draw(self, drawn):
        removed = []
        if drawn >= len(self.contents):
            removed = self.contents
            self.contents = []
            return removed
            for x in range(drawn):
                append a random popped value from self.contents to removed.
                (Inotherwords : removed.append(self.contents.pop(random ball) )
        return removed

ill let you figure out how to pick a random ball. if all else fails feel free to have a look at my