beer.py 566 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. """
  3. A Python version of the classic "bottles of beer on the wall" programming
  4. example.
  5. By Guido van Rossum, demystified after a version by Fredrik Lundh.
  6. """
  7. import sys
  8. n = 100
  9. if sys.argv[1:]:
  10. n = int(sys.argv[1])
  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"
  15. for i in range(n, 0, -1):
  16. print(bottle(i), "on the wall,")
  17. print(bottle(i) + ".")
  18. print("Take one down, pass it around,")
  19. print(bottle(i-1), "on the wall.")