Created
July 27, 2019 18:23
-
-
Save An-Nguyen1/27ba83bda7c2ada1f54db8371b8eec6b to your computer and use it in GitHub Desktop.
Simulate as much coin flip as your computer cane handle
This file contains hidden or 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