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.79 in 38 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
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
This example demonstrates the simplicity | Gerold Penz | 07/23/05 | 15 | |
Creative version | Schizo | 11/06/05 | 16 | |
Advanced, extensible beer/wall framework | Jamie Turner | 05/17/06 | 7 | |
minimal version | Oliver Xymoron | 04/20/05 | 5 | |
using lambda in LISP style | J Adrian Zimmer | 11/14/06 | 2 | |
Exception based | Michael Galpin | 02/08/08 | 0 | |
functional, w/o variables or procedures | Ivan Tkatchev | 07/14/05 | 2 | |
Fully compliant version | Ricardo Garcia Gonzalez | 01/15/06 | 7 | |
Using a iterator class | Eric Moritz | 01/20/06 | 2 | |
New conditional expressions in 2.5 | Ezequiel Pochiero | 12/18/06 | 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!
Comments
Sean McKean said on 06/21/05 23:09:41
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
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
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])))