It looks like you had a web site update and now I cannot submit my last project.
Please help.
Your code so far
import copy
import random
Consider using the modules imported above.
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
successes = 0
#print(expected_balls)
for n in range(num_experiments):
fail = False
x = copy.deepcopy(hat)
result = x.draw(num_balls_drawn)
#print (str(result))
if "yellow" in expected_balls.keys() and expected_balls["yellow"] > result.count("yellow"):
fail = True
if "red" in expected_balls.keys() and expected_balls["red"] > result.count("red"):
fail = True
if "green" in expected_balls.keys() and expected_balls["green"] > result.count("green"):
fail = True
if "blue" in expected_balls.keys() and expected_balls["blue"] > result.count("blue"):
fail = True
if not fail:
successes += 1
#print("Success")
#print(successes)
return successes/num_experiments
class Hat:
def init(self, yellow=0,red=0,green=0,blue=0,test=0):
self.contents = list()
for b in range(yellow):
self.contents.append("yellow")
for b in range(red):
self.contents.append("red")
for b in range(green):
self.contents.append("green")
for b in range(blue):
self.contents.append("blue")
def draw(self, balls=0):
out = list()
urn = copy.copy(self.contents)
for x in range(balls):
r = random.randrange(len(self.contents))
out.append(self.contents[r])
self.contents.remove(self.contents[r])
if len(self.contents)==0:
self.contents = copy.copy(urn)
return out
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36.
Challenge: Probability Calculator
Link to the challenge: