Tell us what’s happening:
Describe your issue in detail here.
Every time I run the code, same aleatory numbers are created.
Your code so far
import copy
import random
# Consider using the modules imported above.
class Hat:
def __init__(self,**arguments):
self.contents=[]
for k, j in arguments.items():
while j > 0:
self.contents.append(k)
j-=1
def draw(self, ball_number):
self.removed=[]
if ball_number>len(self.contents):
return self.contents
i=0
while i < ball_number:
aleatory=random.random()
remove=int(aleatory*(len(self.contents)-1))
self.removed.append(self.contents[remove])
self.contents.pop(remove)
i+=1
return self.removed
def experiment(hat, expected_balls, num_balls_drawn, num_experiments):
success=0
for i in range(num_experiments):
tested_hat=copy.copy(hat)
tested_hat.draw(num_balls_drawn)
all_found=1
for k, j in expected_balls.items():
while j>0:
try:
tested_hat.remove(k)
j-=1
except:
j=-1
all_found=0
if all_found==1:
success+=1
probability=success/num_experiments
return probability
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Challenge: Probability Calculator
Link to the challenge: