blob: af58380e0f5a1ae8dd852814f2c877f59b12de7e [file] [log] [blame]
Georg Brandl856898b2010-12-30 22:11:50 +00001#!/usr/bin/env python3
Georg Brandl4630c092009-10-10 21:49:24 +00002
Georg Brandl856898b2010-12-30 22:11:50 +00003"""
4A Python version of the classic "bottles of beer on the wall" programming
5example.
6
7By Guido van Rossum, demystified after a version by Fredrik Lundh.
8"""
Georg Brandl4630c092009-10-10 21:49:24 +00009
Guido van Rossumb55f9ff1998-12-21 18:30:20 +000010import sys
Georg Brandl4630c092009-10-10 21:49:24 +000011
Guido van Rossumb55f9ff1998-12-21 18:30:20 +000012n = 100
Georg Brandl4630c092009-10-10 21:49:24 +000013if sys.argv[1:]:
14 n = int(sys.argv[1])
15
Guido van Rossumb55f9ff1998-12-21 18:30:20 +000016def bottle(n):
17 if n == 0: return "no more bottles of beer"
18 if n == 1: return "one bottle of beer"
19 return str(n) + " bottles of beer"
Georg Brandl4630c092009-10-10 21:49:24 +000020
21for i in range(n, 0, -1):
22 print(bottle(i), "on the wall,")
23 print(bottle(i) + ".")
Collin Winter6f2df4d2007-07-17 20:59:35 +000024 print("Take one down, pass it around,")
Georg Brandl4630c092009-10-10 21:49:24 +000025 print(bottle(i-1), "on the wall.")