Build a Probability Calculator Project - Build a Probability Calculator Project

Tell us what’s happening:

Build a Probability Calculator Project - Experiment Method.
I have develop a code which I believe has a right logic, but still getting error that result is not correct.
My code is as below, would pls let me know where I am doing wrong

Your code so far

import copy
import random

class Hat:

    def __init__(self, **args):
        self.contents = [ball for ball in args for value in range(args[ball])]
        #print('args** , contents', args, self.contents)
    def draw(self, num):
        drawn_balls = []

        if num > len(self.contents):
            num = len(self.contents)

        for ball in range(num):
            ball = random.choice(self.contents)
            drawn_balls.append(ball)
            self.contents.remove(ball)

        return drawn_balls
    
    def get_contents(self):
        return (self.contents, '\n', len(self.contents))

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):

   
    count_expected = 0
    M = 0

    for i in range (num_experiments):
        copy_hat = copy.deepcopy(hat)
        drawn_balls = copy_hat.draw(num_balls_drawn)

        for k in expected_balls:
            if expected_balls[k] == drawn_balls.count(k):
                count_expected += 1
        if count_expected == len(expected_balls):
            M += 1
        count_expected = 0
 
    result = M/num_experiments
    return f"{result:.3f}" 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Build a Probability Calculator Project - Build a Probability Calculator Project

figured it out, I was not calculating least number of expected,

my calculation was to be exactly as number of expected balls