-
-
Save ParrotParrot/79afd86edc611a24af05ac855621b98e 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 | |
heads = 0 | |
tails = 0 | |
steps = 0 | |
totalsteps = 0 | |
maxsteps = 0 | |
for j in range (1000): | |
totalsteps = totalsteps + steps | |
if steps > maxsteps: maxsteps = steps | |
heads = 0 | |
tails = 0 | |
steps = 0 | |
for i in range(1000000): | |
if (random.randint(0,1)==1): | |
heads=heads+1 | |
else: tails = tails+1 | |
if tails*3 < heads: | |
steps=steps+1 | |
print (str(steps) + " steps, " + str(heads) + " heads and " + str(tails) + " tails") | |
print (str(totalsteps) + " steps taken over 1000 trials, maximum of "+ str(maxsteps) + " steps taken") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment