Tell us what’s happening:
I’m struggling with the 3rd test on this project. I’ve looked at other people’s code on the forum but I can’t see where I’m going wrong. I am also unable to find the test data that this test uses (I’ve tried using F12 but I can’t find the data). Any help would be appreciated!
Your code so far
import copy
import random
class Hat:
def __init__(self,**kwargs):
self.contents = []
for kwarg in kwargs:
for i in range(kwargs[kwarg]):
self.contents.append(kwarg)
def draw(self,no_draws):
removals = []
if no_draws > len(self.contents):
return self.contents
for i in range(no_draws):
selection = random.choice(self.contents)
self.contents.remove(selection)
removals.append(selection)
return removals
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
success = 0
for i in range(num_experiments):
sacrificial = copy.deepcopy(hat)
results = sacrificial.draw(num_balls_drawn)
valid = True
for colour in expected_balls:
if results.count(colour) < expected_balls[colour]:
valid = False
break
if valid:
success += 1
prob = success/num_experiments
return prob
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Challenge Information:
Build a Probability Calculator Project - Build a Probability Calculator Project