newbie: good reasons for learning Python?

Sean Ross sross at connectmail.carleton.ca
Fri Jun 20 19:47:38 EDT 2003


Better yet, go here:
http://99-bottles-of-beer.ls-la.net/

And browse how each language solves this relatively simple problem. (This is
how I discovered Python, BTW.)
I found only two implementations I liked better than the Python version (not
the minimal one): Smalltalk's and Ruby's.
They've replaced the Ruby one I liked with a very long winded version,
however. The one I liked was more like this:

99.downto(1)  do | i |
    puts "#{ i } bottle#{ 's' if i > 1 } of beer on the wall"
    puts "#{ i } bottle#{ 's' if i > 1 } of beer"
    puts "take one down, pass it around"
    puts "#{ i==1 ? 'no' : i-1 } bottle#{ 's' if i != 2 } of beer on the
wall\n"
end

Seeing how different languages solve the same problem can help you decide
which languages you'd like to learn (and not learn!).
This particular problem exhibits a languages' use of looping and conditional
constructs, as well as display (which are the meat and potatoes of
programming).

BTW, you can do something similar to the Ruby version in Python, though the
"and/or" idiom is *strongly* discouraged for its potential pitfalls. (Let's
go, PEP 308!  heh)

for i in xrange(99, 0, -1):
    print "%s bottle%s of beer on the wall" % (i, i > 1 and 's' or '')
    print "%s bottle%s of beer" % (i, i > 1 and 's' or '')
    print "take one down, pass it around"
    print "%s bottle%s of beer on the wall\n" % (i==1 and 'no' or i-1, i !=
2 and 's' or '')






More information about the Python-list mailing list