-
-
Save TheTechRobo/76fabc61e5f77f358e4835085cc98086 to your computer and use it in GitHub Desktop.
Simulate as many coin flips as your computer can handle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
thanks to An-Nguyen1 for the original gist