Advertisement
small_ing

coinflipTest.py

Dec 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. import random
  2. heads = 50
  3. tails = 50
  4. counter = 0
  5. while heads <= 83:
  6.     heads = 0
  7.     tails = 0
  8.     for num in range(100):
  9.         rand = random.randrange(3)
  10.         if rand % 2 == 0:
  11.             heads += 1
  12.         else:
  13.             tails += 1
  14.     s = "There were {heads} heads and {tails} tails flipped out of 100.".format(heads=heads, tails=tails)
  15.     print(s)
  16.     counter += 1
  17. print("It took " + str(counter) + " runs to get a split of {heads} to {tails}.".format(heads=heads, tails=tails))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement