Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Python

(using lambda in LISP style)

Date:11/14/06
Author:J Adrian Zimmer
URL:http://jazimmer.net
Comments:0
Info:http://python.org
Score: (3.07 in 15 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) ] )

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
This example demonstrates the simplicityGerold Penz07/23/054
Creative versionSchizo11/06/0512
minimal versionOliver Xymoron04/20/053
Advanced, extensible beer/wall frameworkJamie Turner05/17/063
Exception basedMichael Galpin02/08/080
Using a iterator classEric Moritz01/20/062
Fully compliant versionRicardo Garcia Gonzalez01/15/065
New conditional expressions in 2.5Ezequiel Pochiero12/18/060
functional, w/o variables or proceduresIvan Tkatchev07/14/051
minimal version with singularEmlyn Jones06/13/052

Comments

Download Source | Write Comment

Add Comment

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.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: