def first_head():
coin=0
count=0
while coin == 0:
coin = randint(0,1)
count += 1
return count
@interact
def _(price= [5,10,15,20], nGames = [100,1000,10000,100000]):
accumulation = 0
sequence = []
daily = []
for _ in range(nGames):
fh = first_head()
sequence.append(fh)
accumulation += 2^fh-price
daily.append(accumulation)
totalPayout = 0
for i in range(len(sequence)):
totalPayout += 2^sequence[i]
avg = float(totalPayout/nGames)
longestRun=max(sequence)
longestRunIndex=sequence.index(longestRun)
print('Luckiest: game # %s, first head at position %s, winning $%s.'%(longestRunIndex, longestRun, 2^longestRun))
print('Lowest: %s'%min(daily))
print('Highest: %s'%max(daily))
print('Final: %s'%daily[nGames-1])
print('Average payout: %s.'%avg)
l=list_plot(daily,plotjoined = True,gridlines=True)
show(l)