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

(minimal version with singular)

Date:06/13/05
Author:Emlyn Jones
URL:n/a
Comments:3
Info:http://www.python.org
Score: (2.69 in 36 votes)
a,t="\n%s bottle%s of beer on the wall","\nTake one down, pass it around"
for d in range(99,0,-1):print(a%(d,"s"*(not d-1==0))*2)[:-12]+t+a%(d-1 or 'No',"s"*(not d-2==0))

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
This example demonstrates the simplicityGerold Penz07/23/0515
Creative versionSchizo11/06/0516
Advanced, extensible beer/wall frameworkJamie Turner05/17/067
minimal versionOliver Xymoron04/20/055
functional, w/o variables or proceduresIvan Tkatchev07/14/052
using lambda in LISP styleJ Adrian Zimmer11/14/062
Fully compliant versionRicardo Garcia Gonzalez01/15/067
Exception basedMichael Galpin02/08/080
Using a iterator classEric Moritz01/20/062
New conditional expressions in 2.5Ezequiel Pochiero12/18/061

Comments

>>  Sean McKean said on 06/21/05 23:09:41

Sean McKean Here's a shorter version (163 bytes) that includes punctuation:

a,s="\n%s bottle","s of beer on the wall,"
for d in range(99,0,-1):print((a%d+s[d==1:])*2)[:-13]+",\nTake one down, pass it around,"+a%(d-1 or"No";)+s[d==2:-1]+"."

>>  Sean McKean said on 06/21/05 23:29:58

Sean McKean Sorry, didn't know about the 100 character line limit.
Here's the correct version:

a,s,t="\n%s bottle","s of beer on the wall,",",\nTake one down, pass it around,"
for d in range(99,0,-1):print((a%d+s[d==1:])*2)[:-13]+t+a%(d-1 or"No";)+s[d==2:-1]+"."

>>  vogletron said on 06/05/09 14:23:25

vogletron Based on the one in the last comment but less compact (268 bytes), matching 99-bottles-of-beer.net/lyrics exactly, and in one-liner form:

print(lambda A:'\n\n'.join([(A(n)*2)[:-14].capitalize()+'.\n'+('Take one down and pass it around, '*(n!=0)or'Go to the store and buy some more, ')+A((n-1)%100)[:-2]+'.'for n in xrange(99,-1,-1)]))(lambda n:("%s bottle%s of beer on the wall, "%(n or'no more','s'[:n!=1])))

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: