Need some help with Probability Calculator

Hey!
It seems to me like the calculator is working fine, but can’t pass the tests. Could you give any advice to fix this?

Here is the link to my replit:

import random
class Hat:
def init(self, **kwargs):
self.contents =
for ele in kwargs:
for time in range(kwargs[ele]):
self.contents.append(ele)
def draw(self, num_balls):
self.list_of_strings =
self.contents_copy = self.contents.copy()
if num_balls >len(self.contents):
self.list_of_strings = self.contents
else:
for time in range(num_balls):
ball = random.choice(self.contents_copy)
self.contents_copy.remove(ball)
self.list_of_strings.append(ball)
return self.list_of_strings

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
count_true = 0
for one in range(num_experiments):
state = True
working_list = hat.draw(num_balls_drawn)
for k in expected_balls.keys():
if working_list.count(k) < expected_balls[k]:
state = False
if state:
count_true += 1

return count_true/num_experiments

Read the error message:
AssertionError: 7 != 5 : Expected hat draw to reduce number of items in contents.

You are supposed to reduce the contents in the hat during the draw.
This obviously will cause some trouble for the experiment, so you need to figure out how to deal with that.

1 Like

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