real language

## Language Python

(using lambda in LISP style)

 Date: 11/14/06 Author: J Adrian Zimmer URL: http://jazimmer.net Comments: 2 Info: http://python.org Score: (2.83 in 35 votes)
```# Readable Python Version of "99 Bottles of Beer" Program
# Well, its readable if you know Python reasonably well.
# Public Domain by J Adrian Zimmer [[ jazimmer.net ]]

verse1 = lambda x: \
"""%s of beer on the wall, %s of beer.
Take one down, pass it around, %s of beer on the wall.
""" % (bottle(x),bottle(x),bottle(x-1))

verse2 = \
"""No more bottles of beer on the wall, no more bottles of beer.
Go to the store, buy some more, 99 bottles of beer on the wall.
"""

def verse(x):
if x==0:     return verse2
else:        return verse1(x)

def bottle(x):
if x==0:   return "no more bottles"
elif x==1: return str(x) + " bottle"
else:      return str(x) + " bottles"

print "\n".join( [ verse(x) for x in range(99,-1,-1) ] )```

## Alternative Versions

This example demonstrates the simplicityGerold Penz07/23/0515
Creative versionSchizo11/06/0516
minimal versionOliver Xymoron04/20/055
functional, w/o variables or proceduresIvan Tkatchev07/14/052
Fully compliant versionRicardo Garcia Gonzalez01/15/067
minimal version with singularEmlyn Jones06/13/053
Exception basedMichael Galpin02/08/080
Using a iterator classEric Moritz01/20/062
New conditional expressions in 2.5Ezequiel Pochiero12/18/061

said on 07/15/09 22:36:11

It could be made more functional:

def verse(x):
return verse2 if x == 0 else verse1 (x)

def bottle(x):
return "no more bottles" if x == 0 else "%d bottle%s" % (x, "" if x == 1 else "s"

nallias said on 12/02/09 09:20:16

Another version of a Lisp-like code:

i=0
wall=(i==1) and (lambda i: str(i)+" bottle of beer on the wall, "+str(i)+" bottle of beer!\nTake one down, pass it around,\n"+str(i-1)+" bottles of beer on the wall!\n" or (lambda i: str(i)+" bottle of beer on the wall, "+str(i)+" bottle of beer!\nTake one down, pass it around,\nNo bottles of beer on the wall!\n"
for i in range(99,0,-1):
print wall(i)

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.