Guest User

Untitled

a guest
Jan 28th, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. times = 1000000
  2. count_1 = 0
  3. count_all = 0
  4.  
  5. for _ in range(times):
  6. balls = [math.floor(random.random()*2), math.floor(random.random()*2), math.floor(random.random()*2)] # set balls to 0 or 1 at random
  7.  
  8. # pick first ball at random and remove it from balls
  9. first_pick_index = math.floor(random.random()*3)
  10. first_pick = balls[first_pick_index]
  11. balls = balls[:first_pick_index] + balls[first_pick_index+1:]
  12.  
  13. # pick second ball at random and remove it from balls
  14. second_pick_index = math.floor(random.random()*2)
  15. second_pick = balls[second_pick_index]
  16. balls = balls[:second_pick_index] + balls[second_pick_index+1:]
  17.  
  18. if first_pick == 1 and second_pick == 1:
  19. count_all += 1
  20. if balls[0] == 1: # if last ball is 1
  21. count_1 += 1
  22.  
  23. print(count_1, count_all)
Advertisement
Add Comment
Please, Sign In to add comment