Hi, I started the Freecode Camp Scientific Computing with python. I went trough the videos and began completing the projects. I’m trying to finish the last one but I get an error from the last unit test, I get 0.257 instead of the 0.272 expected. I have been looking for an answer but didin’t find any solution.
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}")
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.