Advertisement
esuvii

coinflips.py

May 25th, 2024
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import random
  2. import sys
  3.  
  4. def flip(players):
  5.     success = 0
  6.     for p in range(players):
  7.         outcome = random.randint(0,1)
  8.         if outcome == 1:
  9.             success += 1
  10.     return success
  11.  
  12. def trial():
  13.     players = 1000
  14.     for t in range(10):
  15.         players = flip(players)
  16.     return players
  17.    
  18. outcomes = {}
  19. n = 1000000
  20. update = 10000
  21. for i in range(n):
  22.     result = trial()
  23.     if result in outcomes:
  24.         outcomes[result] +=1
  25.     else:
  26.         outcomes[result] = 1
  27.        
  28.     if i%update == 0:
  29.         progress = str(round(100*(i+1)/n))
  30.         sys.stdout.write(""\r"" + progress + ""%     "")
  31.         sys.stdout.flush()
  32.  
  33. print(outcomes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement