Created
January 13, 2015 14:24
-
-
Save rhettallain/d834cce099e7cd29b174 to your computer and use it in GitHub Desktop.
Money won in a coin flipping game
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 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