Basic coin flipper program - logical error help
Jeffrey Schwab
jeff at schwabcenter.com
Wed Feb 22 09:16:48 EST 2006
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)
More information about the Python-list
mailing list