1 | n/a | #!/usr/bin/env python3 |
---|
2 | n/a | |
---|
3 | n/a | """ |
---|
4 | n/a | A Python version of the classic "bottles of beer on the wall" programming |
---|
5 | n/a | example. |
---|
6 | n/a | |
---|
7 | n/a | By Guido van Rossum, demystified after a version by Fredrik Lundh. |
---|
8 | n/a | """ |
---|
9 | n/a | |
---|
10 | n/a | import sys |
---|
11 | n/a | |
---|
12 | n/a | n = 100 |
---|
13 | n/a | if sys.argv[1:]: |
---|
14 | n/a | n = int(sys.argv[1]) |
---|
15 | n/a | |
---|
16 | n/a | def bottle(n): |
---|
17 | n/a | if n == 0: return "no more bottles of beer" |
---|
18 | n/a | if n == 1: return "one bottle of beer" |
---|
19 | n/a | return str(n) + " bottles of beer" |
---|
20 | n/a | |
---|
21 | n/a | for i in range(n, 0, -1): |
---|
22 | n/a | print(bottle(i), "on the wall,") |
---|
23 | n/a | print(bottle(i) + ".") |
---|
24 | n/a | print("Take one down, pass it around,") |
---|
25 | n/a | print(bottle(i-1), "on the wall.") |
---|