# Build a Probability Calculator Project - Completely lost on the third test

### Tell us what’s happening:

I cannot get past the third test and I’ve been trying it for many hours now. Is something else affecting my draw method that I’m not seeing?

“If the number of balls to draw exceeds the available quantity, return all the balls.”
What is wrong with my implementation? Putting negatives and zero just gives zero and values exceeding and equal to number of balls gives 1.

### Your code so far

``````import copy
import random

class Hat:
def __init__(self, **kwargs):
self.contents = []
for colour in kwargs:
if not kwargs[colour] > 0:
continue
for _ in range(kwargs[colour]):
self.contents.append(str(colour))

def draw(self, num):
if num >= len(self.contents):
return self.contents

return [
self.contents.pop(
random.randint(0, len(self.contents) - 1)) for _ in range(num)
]

def experiment(
hat, expected_balls, num_balls_drawn, num_experiments
):
count = 0

for _ in range(num_experiments):
experiment_hat = copy.deepcopy(hat)
experiment_list = experiment_hat.draw(num_balls_drawn)

valid = True
for ball in expected_balls:
if experiment_list.count(ball) >= expected_balls[ball]:
continue
else:
valid = False
break
if valid:
count += 1

return count / num_experiments

# hat = Hat(black=6, red=4, green=3)
# probability = experiment(hat=hat,
#                   expected_balls={
#                     "red":2,"green":1},
#                   num_balls_drawn=5,
#                   num_experiments=2000)

# print(probability)

``````

### Your browser information:

User Agent is: `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36`

### Challenge Information:

Build a Probability Calculator Project - Build a Probability Calculator Project

you need to also remove the returned from the Hat, like the other case. `self.contents` need to be empty after the draw method execute in this case