# Help: Probability Calculator

Hello, I need help with the second part of the exercise, the results are out of range. Please help.

``````import copy
import random

# Consider using the modules imported above.

class Hat:
def __init__(self, **kwargs):
self.contents = []
nombres = list(kwargs.keys())
for y in range(len(nombres)):
self.contents.append(nombres[y])

def draw(self, quitar_bolas):
if quitar_bolas > len(self.contents):
return self.contents
else:
for x in range(quitar_bolas):
aleatorio = random.randrange(len(self.contents))
self.contents = self.contents

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
for k, v in expected_balls.items():
for _ in range(v):
filtro = []
for x in range(num_experiments):
copia = copy.deepcopy(hat)
result = copia.draw(num_balls_drawn)
for item in result:
k, v = f'{item}', result.count(item)

#   Erase
#
#    i = 0
#    for it in expected_balls.items():
#        for a in [tuple(x.items()) for x in filtro]:
#            if it in a:
#                k = it, a
#                i += 1
#    return i/num_experiments
#
``````

Fixed and working.

``````import copy
import random
# Consider using the modules imported above.

class Hat:
def __init__(self, **kwargs):
self.contents = []
nombres = list(kwargs.keys())
for y in range(len(nombres)):
self.contents.append(nombres[y])

def draw(self, quitar_bolas):
if quitar_bolas > len(self.contents):
return self.contents
else:
for x in range(quitar_bolas):
aleatorio = random.randrange(len(self.contents))
self.contents = self.contents

def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
for k, v in expected_balls.items():
for _ in range(v):
filtro = []
for x in range(num_experiments):
copia = copy.deepcopy(hat)
result = copia.draw(num_balls_drawn)
lista_nombres = []
for item in result:
k, v = f'{item}', result.count(item)
for y in range(len(name)):
for x in range(canti[y]):
lista_nombres.append(name[y])
filtro.append(sorted(lista_nombres))

lll = 0
for xa in filtro:
ix = 0
res_while = []
res_while.append(True)
else:
res_while.append(False)
ix += 1
if False not in res_while:
lll += 1
return float(lll/num_experiments)

``````

It cost me, I managed to solve it, I leave my solution.

My solution.

@tomvalfue92 We cannot see the solution via the link you posted. It just brings us to a login page.