import random
totalsteps = 0
for i in range(100000000):
sum = 0.0
steps = 0
while sum < 1.0:
sum += random.random()
steps += 1
totalsteps += steps
print('AVG STEPS: ' + str(totalsteps / i))
It's funny. I read the problem, estimated that it was "probably 2 or 3" and then wasn't all that surprised to find that the solution was e. The derivation of it is pretty cool, too.