>>7262628sorry I forgot to subtract max by na so it gave 1/3 instead of 2/3
import random
yes = 0 #this will track whether the second ball we drew was gold
no = 0 #this will track how whether the second ball we drew was grey
na = 0
#G = gold , b = grey
b1 = ["g", "g"]
b2 = ["g", "b"]
b3 = ["b", "b"]
boxes = (b1,b2,b3)
top = 10000
if True:
for a in range(0,top) :
curbox = boxes[random.randint(0,2)] #chose a random box
picked = random.randint(0,1)
if curbox == b3 :
na += 1 #we chose box 3 so that dosen't matter
elif curbox[picked] == "g":
del curbox[picked] # remove the ball you picked up from the box
if curbox[0] == "g": # check if the second ball is gold
yes += 1
else:
no += 1
else : # we chose grey at the first try so it dosen't matter
na += 1
#re initialize boxes because some were deleted
b1 = ["g", "g"]
b2 = ["g", "b"]
b3 = ["b", "b"]
boxes = (b1,b2,b3)
print ("times the gold ball was drawn a second time:", yes)
print ("times the silver ball was drawn a second time:" , no)
print ("trials we had to throw away because it didn't match our pre conditions:" , na)
print ("chance of drawing a gold ball the second time:", yes/(top-na))
input ("press enter to stop")