An error like this means you are not counting some draws that are good, so the bug has to be where you are counting good experiments in your experiment()
function. If you take your code:
for color in balls_drawn:
if (color in expected_balls) and (color not in colors):
if (balls_drawn.count(color) >= expected_balls[color]):
colors.append(color)
#print (color, expected_balls[color], balls_drawn.count(color))
#print (color, expected_balls[color])
#print (colors)
if (colors == expected_colors) or (colors == expected_colors.reverse()):
print("GOOD")
M += 1
break
and add some print()
statements:
good = False
for color in balls_drawn:
if (color in expected_balls) and (color not in colors):
if (balls_drawn.count(color) >= expected_balls[color]):
colors.append(color)
#print (color, expected_balls[color], balls_drawn.count(color))
#print (color, expected_balls[color])
#print (colors)
if (colors == expected_colors) or (colors == expected_colors.reverse()):
# print("GOOD")
good = True
print(f"GOOD drawn: {balls_drawn} expected: {expected_balls}")
M += 1
break
if not good:
print(f"BAD drawn: {balls_drawn} expected: {expected_balls}")
You’ll get ouput like this:
BAD drawn: ['red', 'blue', 'blue', 'green'] expected: {'blue': 2, 'green': 1}
which shows that your code missed a good draw. I would check how you are comparing the drawn balls and expected balls, especially the last conditional. Since there are more than two colors, I don’t think colors
and expected_colors
can be expected to be equal or to the other’s reverse.
Good luck.