Guido van Rossum | b55f9ff | 1998-12-21 18:30:20 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Georg Brandl | 22fff43 | 2009-10-27 20:19:02 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | b55f9ff | 1998-12-21 18:30:20 +0000 | [diff] [blame] | 3 | # By GvR, demystified after a version by Fredrik Lundh. |
Georg Brandl | 22fff43 | 2009-10-27 20:19:02 +0000 | [diff] [blame] | 4 | |
Guido van Rossum | b55f9ff | 1998-12-21 18:30:20 +0000 | [diff] [blame] | 5 | import sys |
Georg Brandl | 22fff43 | 2009-10-27 20:19:02 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | b55f9ff | 1998-12-21 18:30:20 +0000 | [diff] [blame] | 7 | n = 100 |
Georg Brandl | 22fff43 | 2009-10-27 20:19:02 +0000 | [diff] [blame] | 8 | if sys.argv[1:]: |
| 9 | n = int(sys.argv[1]) |
| 10 | |
Guido van Rossum | b55f9ff | 1998-12-21 18:30:20 +0000 | [diff] [blame] | 11 | def bottle(n): |
| 12 | if n == 0: return "no more bottles of beer" |
| 13 | if n == 1: return "one bottle of beer" |
| 14 | return str(n) + " bottles of beer" |
Georg Brandl | 22fff43 | 2009-10-27 20:19:02 +0000 | [diff] [blame] | 15 | |
| 16 | for i in range(n, 0, -1): |
| 17 | print(bottle(i), "on the wall,") |
| 18 | print(bottle(i) + ".") |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame] | 19 | print("Take one down, pass it around,") |
Georg Brandl | 22fff43 | 2009-10-27 20:19:02 +0000 | [diff] [blame] | 20 | print(bottle(i-1), "on the wall.") |