newbie: good reasons for learning Python?

Sean Ross sross at connectmail.carleton.ca
Tue Jun 24 13:49:44 EDT 2003


"Mel Wilson" <mwilson at the-wire.com> wrote in message
news:JcI9+ks/KLAC089yn at the-wire.com...
>    Inspiring.  But after I'd improved on it, I went to the
> web site and found out I'd only recreated the programs you
> were writing an alternative to.  Oh well.

Actually, I wasn't trying to make an alternative to that code, I was just
trying to write something similar to the Ruby version I showed.
But, while we're here:

# version of Fredrik Lundh's code at
# http://99-bottles-of-beer.ls-la.net/p.html#Python
# using dict.get() rather than try/except
verse = """
%(b1)s on the wall, %(b1)s,
take one down, pass it around,
%(b0)s on the wall.
"""

def bottle(n):
    return {0: "no more bottles",
                1: "1 bottle"}.get(n, "%d bottles"%n) + " of beer"

for i in range(99, 0, -1):
    b1, b0 = bottle(i), bottle(i-1)
    print verse % locals()






More information about the Python-list mailing list