Everyone knows "99 bottles of beer on the wall".
Mat's Mug made a comment about mugs on the wall in The 2nd Monitor and I realized I never wrote a "beer on the wall" program. But that seemed way too easy, so I made it a "n number of x on the y" instead. It also seemed like a good excuse to use templates in Python, which I hadn't done before.
import sys n = int(sys.argv) x = sys.argv y = sys.argv template = '''\ %i %s on the %s %i %s Take one down, pass it around %i %s on the %s ''' for n in range(n, 0, -1): print template % (n, x, y, n, x, n-1, x, y)
python script.py 99 "mugs of beer" wall
For obvious reasons there's no way (that I know of) to remove multiples of
n = 1. Sure, it's not hard to turn
mugs of beer into
mug of beer, but it's generic. One can input anything and I can't catch all methods of pluralization.
I prefer readability over 'clever code' and my naming is probably not too good.