Tell us what’s happening:
Please help me to solve code so far!!! Thx so much.
Your code so far
import copy
import random
class Hat:
def __init__(self, **kwargs):
self.contents = []
for arg in kwargs:
for i in range(0, kwargs[arg]):
self.contents.append(arg)
def draw(self, amount):
temp = copy.copy(self.contents)
drawn = []
if amount >= len(temp):
return temp
for i in range(0, amount):
rand = random.choice(temp)
drawn.append(rand)
temp.pop(temp.index(rand))
self.contents = temp
return drawn
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
success = 0
for i in range(0, num_experiments):
print("experiment:", i)
test = copy.deepcopy(hat)
balls = test.draw(num_balls_drawn)
counts = {}
match = True
for ball in balls:
counts[ball] = counts.get(ball, 0) + 1
for color in expected_balls:
if counts.get(color, 0) < expected_balls[color]:
match = False
if match:
success = success + 1
return success / num_experiments
Your browser information:
User Agent is: Mozilla/5.0 (iPad; CPU OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/127.0.6533.56 Mobile/15E148 Safari/604.1
Challenge Information:
Build a Probability Calculator Project - Build a Probability Calculator Project