python newbie
Peter Hansen
peter at engcorp.com
Sun Apr 7 22:55:38 EDT 2002
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. Conciseness is not a good goal, IMHO,
unless you choose Perl as your implementation language.
-Peter
More information about the Python-list
mailing list