python newbie

Chris chris at cmb-enterprises.com
Mon Apr 8 01:25:08 EDT 2002


In article <3CB106AA.1AA3A5BF at engcorp.com>,
 Peter Hansen <peter at engcorp.com> wrote:

> Chris wrote:
> > 
> > In article <Xns91E989929996CRASXnewsDFE1 at 130.133.1.4>,
> >  Philip Swartzleonard <starx at pacbell.net> wrote:
> > 
> > > def percent_chance( percentage ):
> > >       "Assumes percentage as number 0-100"
> > >       if random.random() > (percentage / 100.0):
> > >               return 1
> > >       else:
> > >               return 0
> > 
> > Might more concisely be written as:
> > 
> > def percent_chance( percentage ):
> >      return random.random() > (percentage / 100.0)
> 
> But this is Python, and a newbie.  I think Philip's
> effort was more suited to the audience, as it is
> more readable. 

It's redundant, and "random.random() > (percentage / 100.0)" is no more 
readable with a "if" in front of it than it is with a "return".

I'm not trying to be rude, it just seems silly to do the work twice.

And I commend anyone for learning Python.  The more languages the better!

(Though I wouldn't mind if a few more of them looked like Ruby :-)



More information about the Python-list mailing list