Build a Probability Calculator Project - Build a Probability Calculator Project

Tell us what’s happening:

import copy
import random
class Hat:
def init(self, **kwargs):
self.contents = [k for k, v in kwargs.items() for _ in range(v)]

def draw(self, n):
    n = min(n, len(self.contents))
    return [self.contents.pop(random.randrange(len(self.contents))) for _ in range(n)]

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
m = 0
for _ in range(num_experiments):
another_hat = copy.deepcopy
“I am unable to pass the 3rd test
Please help”

Your code so far

import copy
import random
# Consider using the modules imported above.


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

    def draw(self, n):
        n = min(n, len(self.contents))
        return [self.contents.pop(random.randrange(len(self.contents))) for _ in range(n)]


def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
    m = 0
    for _ in range(num_experiments):
        another_hat = copy.deepcopy(hat)
        balls_drawn = another_hat.draw(num_balls_drawn)
        balls_req = sum([1 for k, v in expected_balls.items() if balls_drawn.count(k) >= v])
        m += 1 if balls_req == len(expected_balls) else 0

    return m / num_experiments

Your browser information:

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

Challenge Information:

Build a Probability Calculator Project - Build a Probability Calculator Project

When the number of ball to draw is equal to the number of balls in the hat the test expects the balls in the exact order of the hat. You are always drawing them randomly.

But why is that a problem??

It’s simply the way that tests has been written. I suppose we are going to change it or clarify that in the instructions.

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