annotate Demo/scripts/beer.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 34999a1aea9b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9669
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #! /usr/bin/env python
56454
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
2
9669
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # By GvR, demystified after a version by Fredrik Lundh.
56454
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
4
9669
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 import sys
56454
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
6
9669
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 n = 100
56454
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
8 if sys.argv[1:]:
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
9 n = int(sys.argv[1])
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
10
9669
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 def bottle(n):
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 if n == 0: return "no more bottles of beer"
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 if n == 1: return "one bottle of beer"
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 return str(n) + " bottles of beer"
56454
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
15
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
16 for i in range(n, 0, -1):
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
17 print bottle(i), "on the wall,"
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
18 print bottle(i) + "."
9669
272eccc573e2 100 bottles of beer on the wall example.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 print "Take one down, pass it around,"
56454
34999a1aea9b Show use of range() step argument nicely.
Georg Brandl <georg@python.org>
parents: 9669
diff changeset
20 print bottle(i-1), "on the wall."