Hi! i have a problem and currently no clue about what’s causing it. I don’t get why the code works well on vsCode but no on replit. this Is my code
import copy
import random
# Consider using the modules imported above.
class Hat:
def __init__(self, **args):
self.contents = []
for k, v in args.items():
self.contents += [k] * v
def draw(self, n):
draws = []
if n > len(self.contents):
return self.contents
for x in range(n):
random_balls = self.contents.pop(int(random.random() * len(self.contents)))
draws.append(random_balls)
return draws
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
M = 0
color_count = 0
for n in range(num_experiments):
my_hat = copy.deepcopy(hat)
balls_drawn = my_hat.draw(num_balls_drawn)
for color in expected_balls:
if balls_drawn.count(color) >= expected_balls[color]:
color_count += 1
if color_count == len(expected_balls):
M += 1
return M / num_experiments
and this is the error I get:
python main.py
Traceback (most recent call last):
File "main.py", line 7, in <module>
probability = prob_calculator.experiment(
File "/home/runner/boilerplate-probability-calculator/prob_calculator.py", line 31, in experiment
if balls_drawn.count(color) >= expected_balls[color]:
AttributeError: 'NoneType' object has no attribute 'count'
exit status 1