Skip to content

Instantly share code, notes, and snippets.

@chrisc24
Created April 24, 2012 04:46
Show Gist options
  • Save chrisc24/2476501 to your computer and use it in GitHub Desktop.
Save chrisc24/2476501 to your computer and use it in GitHub Desktop.
99 Bottles of Beer on the wall
tensPlaceStrings = { 2:"Twenty", 3:"Thirty", 4:"Forty", 5:"Fifty", 6:"Sixty", 7:"Seventy", 8:"Eighty", 9:"Ninety"}
oneToNineteenStrings = {1:"One", 2:"Two", 3:"Three", 4:"Four", 5:"Five", 6:"Six",7:"Seven",8:"Eight",9:"Nine",
10:"Ten",11:"Eleven", 12:"Twelve", 13:"Thirteen", 14:"Fourteen", 15:"Fifteen", 16:"Sixteen",
17:"Seventeen", 18:"Eighteen", 19:"Nineteen"}
def bottlePlural(num):
if num != 1:
return "bottles"
else:
return "bottle"
def numberToString(num):
if num > 99:
print("error")
elif num > 19:
prefixNum = num // 10
postfixNum = num % 10
if postfixNum != 0:
return tensPlaceStrings[prefixNum] + "-" + oneToNineteenStrings[postfixNum]
else:
return tensPlaceStrings[prefixNum]
elif num > 0:
return oneToNineteenStrings[num]
elif num == 0:
return "No More"
for numBottles in reversed(range(1, 100)):
print(numberToString(numBottles) + " " + bottlePlural(numBottles) + " of beer on the wall,")
print(numberToString(numBottles) + " " + bottlePlural(numBottles) + " of beer!")
print("Take one down, pass it around...")
print(numberToString(numBottles-1) + " " + bottlePlural(numBottles-1) + " of beer on the wall!")
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment