Skip to content

Instantly share code, notes, and snippets.

@TheTechRobo
Forked from An-Nguyen1/Coin flip simulator.py
Last active July 27, 2019 19:07
Show Gist options
  • Save TheTechRobo/76fabc61e5f77f358e4835085cc98086 to your computer and use it in GitHub Desktop.
Save TheTechRobo/76fabc61e5f77f358e4835085cc98086 to your computer and use it in GitHub Desktop.
Simulate as many coin flips as your computer can handle
import random
flips = int(input('how many times do you want to flip the coin? '))
outcomes = ['head','tail']
wieghts = [.5,.5]
head=0
tail=0
for flip in range(flips):
h_t = random.choice(outcomes)
if h_t == 'head':
head += 1
else:
tail += 1
def percentage(ht,outcome):
global flips
percent = outcome/flips * 100
print('{}: {}%'.format(ht,"%.2f" % percent))
percentage('head',head)
percentage('tail',tail)
@TheTechRobo
Copy link
Author

thanks to An-Nguyen1 for the original gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment