Are you new? Read the FAQ and catch up on!
1k views

99 Bottles of Beer in Python

This is a python implementation of the typical example 99 bottles of beer.

Python
  1. #!/usr/bin/env python
  2. # -*- coding: iso-8859-1 -*-
  3. """
  4. 99 Bottles of Beer (by Gerold Penz)
  5. Python can be simple, too :-)
  6. """
  7.  
  8. for quant in range(99, 0, -1):
  9.    if quant > 1:
  10.       print quant, "bottles of beer on the wall,", quant, "bottles of beer."
  11.       if quant > 2:
  12.          suffix = str(quant - 1) + " bottles of beer on the wall."
  13.       else:
  14.          suffix = "1 bottle of beer on the wall."
  15.    elif quant == 1:
  16.       print "1 bottle of beer on the wall, 1 bottle of beer."
  17.       suffix = "no more beer on the wall!"
  18.    print "Take one down, pass it around,", suffix
  19.    print "--"
  20.  

­

I found it here.

Tags: Python 99 Bottles of Beer

Embed:

Recently viewed:

  1. 99 Bottles of Beer in Python