Created
January 29, 2020 16:16
-
-
Save grahamannett/aabb35e53edca335723b36a874c2e13f to your computer and use it in GitHub Desktop.
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 | |
def coinflip(l): | |
s = '' | |
for i in range(0, l): | |
flip = random.choice(['H', 'T']) | |
s += flip | |
return s | |
def montecarlo(i): | |
numHHHT = 0 | |
numHHHH = 0 | |
for ii in range(0, i): | |
flip_result = coinflip(20) | |
numHHHH += 1 if ("HHHH" in flip_result) else 0 | |
numHHHT += 1 if ("HHHT" in flip_result) else 0 | |
print(f"num HHHT = {numHHHT}") | |
print(f"num HHHH = {numHHHH}") | |
montecarlo(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment