Skip to content

Instantly share code, notes, and snippets.

@ParrotParrot
Created September 28, 2018 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ParrotParrot/79afd86edc611a24af05ac855621b98e to your computer and use it in GitHub Desktop.
Save ParrotParrot/79afd86edc611a24af05ac855621b98e to your computer and use it in GitHub Desktop.
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