wes weston wrote:
> DannyB wrote:
> 
>> I'm just learning Python.  I've created a simple coin flipper program -

...

> Dan,
>    Looping is easier with:
> for x in range(100):
>    if random.randint(0,1) == 0:
>       heads += 1
>    else:
>       tails += 1
> 

Or, continuing with that theme:

        for x in range(N):
                heads += random.randint(0, 1)

As in:

        import random
        N = 100
        heads = 0
        for x in range(N):
                heads += random.randint(0, 1)
        print "%d heads and %d tails." % (heads, N - heads)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to