Probability Calculator need help

I think i dont get the test

import random
import copy

class Hat:
    def __init__(self, **balls):
        self.contents = []
        for k, v in balls.items():
            for i in range(v):

    def draw(self,number):
        listofdraws = []
        choices = []
        if number > len(self.contents):
            return self.contents
            for i in range(number):
                choice = random.choice(self.contents)
         #Removing the choice to append it later
            for i in choices:
        return listofdraws

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
    times = 0
    expected = []
   #Get the expecteds in list(str)
    for k,v in expected_balls.items():
        for i in range(v):
    for time in range(num_experiments):
        choices = hat.draw(num_balls_drawn)

      #Each time the loop begins it does a copy

        c_expected = copy.copy(expected)
        c_choices = copy.copy(choices)
        count = 0
        for i in c_expected:

       # it loops in every object in
      # ['blue', 'blue', 'green']

            if i in c_choices:

   #If for example 'blue' is in (copy)_choices, gets removed

                if count == len(expected):
                    times += 1
    return times/num_experiments

The code fails in the second and third tests, but it seems to work well
(at least in my head).

Traceback (most recent call last):
  File "C:\xxx\", line 27, in test_prob_experiment
    self.assertAlmostEqual(actual, expected, delta = 0.01, msg = 'Expected experiment method to return a different probability.')
AssertionError: 0.248 != 0.272 within 0.01 delta (0.02400000000000002 difference) : Expected experiment method to return a different probability.

What am i doing wrong?
I think I did not understand something of the challenge, like a missconception

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