"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(
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
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:
<[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
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
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(
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
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 ==
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
>
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
>
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):
>
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
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 +=
13 matches
Mail list logo