Skip to content

Instantly share code, notes, and snippets.

@An-Nguyen1
Created July 27, 2019 18:23
Show Gist options
  • Save An-Nguyen1/27ba83bda7c2ada1f54db8371b8eec6b to your computer and use it in GitHub Desktop.
Save An-Nguyen1/27ba83bda7c2ada1f54db8371b8eec6b to your computer and use it in GitHub Desktop.
Simulate as much coin flip as your computer cane 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment