This site is an archive; learn more about 8 years of OpenHatch.

[Pdxpw-staff] '99 bottles of beer' as a loop

Barbara Shaurette barbara.shaurette at gmail.com
Fri Jul 27 20:21:22 UTC 2012


def bottles():
  for i in reversed(range(100)):
    if i > 0:
      print i, "bottles of beer on the wall,", \
        i, "bottles of beer"
      print "Take one down, pass it around,", \
        i-1, "bottles of beer on the wall\n\r"

Or, if you want to get fussy about the pluralization:

def bottles():
  for i in reversed(range(100)):
    if i > 0:
      b = "bottles"
      if i == 1: b = "bottle"
      print i, b, "of beer on the wall,", \
        i, b, "of beer"
      print "Take one down, pass it around,", \
        i-1, "bottles of beer on the wall\n\r"


More information about the Pdxpw-staff mailing list