2010-12-30 18:11:50 -04:00
|
|
|
#!/usr/bin/env python3
|
2009-10-10 18:49:24 -03:00
|
|
|
|
2010-12-30 18:11:50 -04:00
|
|
|
"""
|
|
|
|
A Python version of the classic "bottles of beer on the wall" programming
|
|
|
|
example.
|
|
|
|
|
|
|
|
By Guido van Rossum, demystified after a version by Fredrik Lundh.
|
|
|
|
"""
|
2009-10-10 18:49:24 -03:00
|
|
|
|
1998-12-21 14:30:20 -04:00
|
|
|
import sys
|
2009-10-10 18:49:24 -03:00
|
|
|
|
1998-12-21 14:30:20 -04:00
|
|
|
n = 100
|
2009-10-10 18:49:24 -03:00
|
|
|
if sys.argv[1:]:
|
|
|
|
n = int(sys.argv[1])
|
|
|
|
|
1998-12-21 14:30:20 -04:00
|
|
|
def bottle(n):
|
|
|
|
if n == 0: return "no more bottles of beer"
|
|
|
|
if n == 1: return "one bottle of beer"
|
|
|
|
return str(n) + " bottles of beer"
|
2009-10-10 18:49:24 -03:00
|
|
|
|
|
|
|
for i in range(n, 0, -1):
|
|
|
|
print(bottle(i), "on the wall,")
|
|
|
|
print(bottle(i) + ".")
|
2007-07-17 17:59:35 -03:00
|
|
|
print("Take one down, pass it around,")
|
2009-10-10 18:49:24 -03:00
|
|
|
print(bottle(i-1), "on the wall.")
|