wes weston wrote: > Looping is easier with: > for x in range(100): > if random.randint(0,1) == 0: > heads += 1 > else: > tails += 1
Also, with the functional programming tools of map, filter, and lambda, this code can be reduced to just six lines: import random flips = map(lambda x: random.randrange(2), xrange(100)) heads = len(filter(lambda x: x is 0, flips)) tails = len(filter(lambda x: x is not 0, flips)) print "The coin landed on heads", heads, "times." print "The coin landed on tails", tails, "times." -- http://mail.python.org/mailman/listinfo/python-list