Hi there,
I’ve been trying to complete this Probablility Calculator project, and got so far, but now I have an issue and I can’t even see what is causing it. Sorry for the weird variable names and all the others, I’m a beginner
Problem being described below code
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
_expected_balls = []
for i in expected_balls.items():
for key, value in {i}:
_expected_balls.append([key])
complete = 0
value_list = []
for it in expected_balls.items():
for key, value in {it}:
value_list.append(value)
num_experiments_count = copy.deepcopy(num_experiments)
while num_experiments_count > 0:
# for a in range(num_experiments):
expected_one = 0
expected_two = 0
drawn_balls_nested_list = hat.draw(num_balls_drawn)
for i in drawn_balls_nested_list:
if i == _expected_balls[0]:
expected_one += 1
if i == _expected_balls[1]:
expected_two += 1
if expected_one >= value_list[0] and expected_two >= value_list[1]:
complete += 1
num_experiments_count -= 1
# pr means probability
pr = complete / num_experiments
return pr
I have problems with the complete variable. It should increase every time when the code completes the if statement, but it only increases 1 or 2 times and can’t go any further, though the while loop repeats exactly 2000 times. It is impossible that from 2000 tries it can only fit the condition 0 or 1 times (2 very rarely). Maybe an indentation issue or what? Tried everithing but found no solutions so far
Can you see any problems with the code? Let me know, because anything could help.
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36
.
Challenge: Probability Calculator
Link to the challenge: