I have created a high-level Python random function for a Monte Carlo Simulation in python and my code is running correctly. However, I'm not able to generate a probability to draw: 2 - blue and 2 - purple balls out of 40 balls from a hat. Total balls are 40, 10-red, 10-blue, 10-Yellow, 10-Purple. Following is my code:
import numpy as np
RED, BLUE, YELLOW, PURPLE = 1,2,3,4
def create_hat_of_balls(N):
hat = 10*['1'] + 10*['2'] + 10*['3'] + 10*['4']
val = 0
for num in range(40):
drawing = [random.choice(hat) for num in range(10)]
prob = drawing.count('blue') == 2 and drawing.count('purple') == 2
val += prob
final_prob = val / N
print(f"(Blue, Purple) probability: {100*final_prob}%")
return hat
hat = create_hat_of_balls(10)
print(hat)
Result
(Blue, Purple) probability: 0.0%
['1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2',
'2', '2', '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4',
'4', '4', '4', '4']
How my probability is 0.0% ?
Much appreciating for help.
Aucun commentaire:
Enregistrer un commentaire