I am unable to pass the third test case for the probability calculator project. I am pretty sure that I have done it right and have spent a lot of time figuring out the mistake. The rest of the code works properly. Please let me know what am I missing out as this is the last project that needs to be completed for the certification.
~Thanks
Your code so far
import copy
import random
class Hat:
def __init__(self, **balls):
self.contents = []
for x, y in balls.items():
while y > 0:
self.contents.append(x)
y -= 1
def draw(self, num):
removed = []
if num > len(self.contents):
return self.contents
for _ in range(num):
temp = self.contents.pop(random.randrange(len(self.contents)))
removed.append(temp)
return removed
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
final=0
for _ in range(num_experiments):
copyhat = copy.deepcopy(hat)
temp_list = copyhat.draw(num_balls_drawn)
success=True
for key,value in expected_balls.items():
if temp_list.count(key) < value:
success=False
break
if success:
final+=1
return final/num_experiments
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Challenge Information:
Build a Probability Calculator Project - Build a Probability Calculator Project