from random import randrange trials = 10000 totalflips = 0 # total number of flips over all trials maxflips = 0 # biggest number of flips in a single trial for t in range(trials): count = 1 # we will certainly do the first flip while randrange(2) != 0: count += 1 totalflips += count maxflips = max(count, maxflips) print('Average number of flips', totalflips/trials) print('Maximum number of flips', maxflips)