from numpy import random import numpy import sys from pylab import * def toss(): x = random() if x > 0.5: return 1 else: return 0 def return_mean(n): i = 0 gevinst = [] while i < n: l = 1 k = True while k: if toss(): k = False gevinst += [l] # 2**l l += 1 i += 1 return numpy.mean(gevinst) potens = int(sys.argv[1]) #print return_mean(antall_ganger) p = 1 tab = [] while p <= potens: res = return_mean(10**p) tab += [res] print res p += 1 plot(tab) # xlabel('# of tosses') ylabel('Mean gain') title('Die throw') grid(True) show()