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)

Date:04/20/05
Author:Oliver Xymoron
URL:n/a
Comments:5
Info:n/a
Score: (2.81 in 103 votes)
By Oliver Xymoron (133 Bytes)

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

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
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
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

Comments

>>  Rune Berge said on 06/13/05 14:56:38

Rune Berge Nice and short :)
My only nitpick is that it doesn't handle the singular form of bottles in the two last verses...

>>  John Irby said on 07/12/05 01:02:56

John Irby Maybe add a minimilist input() statement at the bottom for slow readers.

>>  Wen Zhang said on 08/31/06 14:52:30

Wen Zhang We needn't the variable t, just print it directly and save 4 chars.

>>  sitopren said on 02/13/10 14:06:45

sitopren Implementing Wen Zhang's suggestion, it would look like this:
a="\n%s bottles of beer on the wall"
for d in range(99,0,-1):print(a%d*2)[:-12]+"\nTake one down, pass it around"+a%(d-1 or'No')
However, I noticed an error:
"1 bottles of beer on the wall
1 bottles of beer" (no "s" for singular!)
Additionally, punctuation and the last whole stanza are missing. So, the (a bit longer but) correct version (which needs t three times):
a="\n%s bottles of beer on the wall,"
t="\nTake one down and pass it around,"
for d in range(99,1,-1):print(a%d*2)[:-13]+"."+t+a[:-1]%(d-1)+"."
z=a%"no more"
print(2*(a%1).replace("s","";))[:46]+t+z[:-1]+".\nN"+(2*z)[2:61]+".\nGo to the store and buy some more,"+a[:31]%99+"."

>>  Brian said on 09/13/10 21:54:23

Brian But by the time You got to that last bottle, You'd be so drunk, You were pronouncing the word with an 's' at the end. So, it's all good. ;-)

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: