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

(New conditional expressions in 2.5)

Date:12/18/06
Author:Ezequiel Pochiero
URL:n/a
Comments:1
Info:http://www.python.org
Score: (2.41 in 27 votes)
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""99 Bottles of Beer, by Ezequiel Pochiero. (Requires Python 2.5)"""

song=''
for n in range(99,0,-1):
    s1= `n`+(' bottles' if n!=1 else ' bottle')
    s2 = (`n-1` if n-1!=0 else 'no more')+(' bottles' if n!=2 else ' bottle')
    song += '%s of beer on the wall, %s of beer. \n\
Take one down and pass it around, %s of beer on the wall.\n\n' % (s1,s1,s2)

song += 'No more bottles of beer on the wall, no more bottles of beer. \n\
Go to the store and buy some more, 99 bottles of beer on the wall.'

print song

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
using lambda in LISP styleJ Adrian Zimmer11/14/062
Exception basedMichael Galpin02/08/080
functional, w/o variables or proceduresIvan Tkatchev07/14/052
minimal version with singularEmlyn Jones06/13/053
Fully compliant versionRicardo Garcia Gonzalez01/15/067
Using a iterator classEric Moritz01/20/062

Comments

>>  Avi said on 01/08/09 08:25:24

Avi Since backticks are gone in python3.0, this version need to be revised

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: