Re: Basic coin flipper program - logical error help

2006-02-22 Thread Paul McGuire
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > sort, then groupby. > > > import itertools > import random > h,t = [len(list(g)) for k,g in itertools.groupby(sorted([random.randrange(2) > for i in xrange(

Re: Basic coin flipper program - logical error help

2006-02-22 Thread Brian van den Broek
DannyB said unto the world upon 21/02/06 06:14 PM: > I'm just learning Python. I've created a simple coin flipper program - > here is the code: > > [source] > #Coin flipper > import random > > heads = 0 > tails = 0 > counter = 0 > > coin = random.randrange(2) > > while (counter < 100): > i

Re: Basic coin flipper program - logical error help

2006-02-22 Thread Jeffrey Schwab
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:

Re: Basic coin flipper program - logical error help

2006-02-21 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > John Zenger wrote: > > 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)) > > he

Re: Basic coin flipper program - logical error help

2006-02-21 Thread bonono
John Zenger wrote: > 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 i

Re: Basic coin flipper program - logical error help

2006-02-21 Thread John Zenger
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(

Re: Basic coin flipper program - logical error help

2006-02-21 Thread DannyB
Thanks everyone for your insight. I'm coming from C++ - I'm used to formatting code with {} instead of whitespaces. @Larry - this isn't my homework :P I'm actually taking a VB.NET class in school. I was teaching myself C++ but decided to scale back to Python. I've heard it was a bit easier to

Re: Basic coin flipper program - logical error help

2006-02-21 Thread Martin P. Hellwig
DannyB wrote: > I'm just learning Python. So am I :-) > I've created a simple coin flipper program - > here is the code: > > [source] > #Coin flipper > import random > > heads = 0 > tails = 0 > counter = 0 > > coin = random.randrange(2) > > while (counter < 100): > if (coin ==

Re: Basic coin flipper program - logical error help

2006-02-21 Thread wes weston
DannyB wrote: > I'm just learning Python. I've created a simple coin flipper program - > here is the code: > > [source] > #Coin flipper > import random > > heads = 0 > tails = 0 > counter = 0 > > coin = random.randrange(2) > > while (counter < 100): > if (coin == 0): > heads += 1 >

Re: Basic coin flipper program - logical error help

2006-02-21 Thread Larry Bates
DannyB wrote: > I'm just learning Python. I've created a simple coin flipper program - > here is the code: > > [source] > #Coin flipper > import random > > heads = 0 > tails = 0 > counter = 0 > > coin = random.randrange(2) > > while (counter < 100): > if (coin == 0): > heads += 1 >

Re: Basic coin flipper program - logical error help

2006-02-21 Thread Claudio Grondi
DannyB wrote: > I'm just learning Python. I've created a simple coin flipper program - > here is the code: > > [source] > #Coin flipper > import random > > heads = 0 > tails = 0 > counter = 0 > > while (counter < 100): coin = random.randrange(2) Claudio > if (coin == 0): >

Re: Basic coin flipper program - logical error help

2006-02-21 Thread John McMonagle
On Tue, 2006-02-21 at 16:14 -0800, DannyB wrote: > I'm just learning Python. I've created a simple coin flipper program - > here is the code: > > [source] > #Coin flipper > import random > > heads = 0 > tails = 0 > counter = 0 > > coin = random.randrange(2) > > while (counter < 100): > if

Basic coin flipper program - logical error help

2006-02-21 Thread DannyB
I'm just learning Python. I've created a simple coin flipper program - here is the code: [source] #Coin flipper import random heads = 0 tails = 0 counter = 0 coin = random.randrange(2) while (counter < 100): if (coin == 0): heads += 1 counter += 1 else: tails +=