#!/usr/bin/python from __future__ import division import random def spin_is_red(): return random.randrange(38) < 18 def play(turns, start=0, responsibly=False): bank = start bet = 1 for i in xrange(turns): if responsibly and bet > bank: break if spin_is_red(): bank += bet bet = 1 else: bank -= bet bet *= 2 return bank - start def main(): start = 100 trials = 1000 turns = 1000 total = 0 for i in xrange(trials): total += play(turns, responsibly = False) # the way to millions...slowly # total += play(turns, start = start, responsibly = True) # lose print("Expected payout: %s\n" % (total / trials)) main()