Skip to content

Instantly share code, notes, and snippets.

@rhettallain
Created January 13, 2015 14:24
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 rhettallain/d834cce099e7cd29b174 to your computer and use it in GitHub Desktop.
Save rhettallain/d834cce099e7cd29b174 to your computer and use it in GitHub Desktop.
Money won in a coin flipping game
import plotly.plotly as py
from plotly.graph_objs import *
from random import *
from pylab import *
py.sign_in("yourusername", "plotlykey") #you need a plotly account
def flip(N,lose,win):
#N is number of flips
#lose is the amount you lose
#win is the amount you win
total=0
n=1
while n<=N:
bet=choice([lose,win])
total=total+bet
n=n+1
return(total)
M=1000
m=1
money=[]
lost=0 #how many times did you lose money?
while m<=M:
stuff=flip(100,-10,20)
money=money+[stuff]
if stuff<0:
lost=lost+1
m=m+1
data=Data([Histogram(x=money, bins=100)])
plot_url=py.plot(data, filename='coin-flip-histo1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment