import math


def lettersPerOnesPlace(number):
    if number == 1:
        return 3
    if number == 2:
        return 3
    if number == 3:
        return 5
    if number == 4:
        return 4
    if number == 5:
        return 4
    if number == 6:
        return 3
    if number == 7:
        return 5
    if number == 8:
        return 5
    if number == 9:
        return 4
    if number == 0:
        return 4


def lettersPerTensPlace(tens, ones, appendOnesLetters):
    if tens == 1:
        if ones == 1:
            appendOnesLetters[0] = False
            return 6     #eleven
        if ones == 2:
            appendOnesLetters[0] = False
            return 6     #twelve
        if ones == 3:
            appendOnesLetters[0] = False
            return 8     #thirteen
        else:
            return 4     # "teen"
    if tens == 2:
        return 6     #twenty
    if tens == 3:
        return 6     #thirty
    if tens == 4:
        return 5     #forty
    if tens == 5:
        return 5     #fifty
    else:
        return (lettersPerOnesPlace(tens) + 2)   #<onesplace>ty



def lettersPerNumber(number):
    ones = number % 10
    tens = (number - ones) % 100
    hundreds = number - tens - ones

    appendOnesLetters = [True]
    hLetters = lettersPerOnesPlace(hundreds // 100)
    tLetters = lettersPerTensPlace(tens // 10,ones,appendOnesLetters)
    if appendOnesLetters[0]:
        oLetters = lettersPerOnesPlace(ones)
    else:
        oLetters = 0

    if hLetters > 0:
        hLetters += 10  #"hundred and"

    totalLetters = hLetters + tLetters + oLetters
    print "Letters for number ",number,": ",totalLetters,"."


lettersPerNumber(142)
print "One hundred and forty-two"
lettersPerNumber(712)
print "Seven hundred and twelve"
@@ -408,17 +408,47 @@
  return 
-4
+0   #we never actually say zero
 %0A%0A%0Adef l
@@ -806,16 +806,206 @@
 hirteen%0A
+        if ones == 5:%0A            appendOnesLetters%5B0%5D = False%0A            return 7     #fifteen%0A        if ones == 0:%0A            appendOnesLetters%5B0%5D = False%0A            return 3     #ten%0A
         
@@ -1430,16 +1430,55 @@
 - ones%0A%0A
+    if number == 10:%0A        junk = 1%0A%0A
     appe
@@ -1500,16 +1500,41 @@
  %5BTrue%5D%0A
+    if hundreds %3E 0:%0A    
     hLet
@@ -1577,16 +1577,69 @@
 // 100)%0A
+    else:%0A        hLetters = 0%0A%0A    if tens %3E 0:%0A    
     tLet
@@ -1700,16 +1700,48 @@
 etters)%0A
+    else:%0A        tLetters = 0%0A%0A
     if a
@@ -1957,173 +1957,330 @@
     
-print %22Letters for number %22,number,%22: %22,totalLetters,%22.%22%0A%0A%0AlettersPerNumber(142)%0Aprint %22One hundred and forty-two%22%0AlettersPerNumber(712)%0Aprint %22Seven hundred and twelve%22
+return totalLetters%0A%0A%0Adef lettersForAllNumbersUpTo(finalNumber):%0A    runningTotal = 0%0A    for i in range(1,finalNumber):%0A        runningTotal += lettersPerNumber(i)%0A        print i,%22 has %22,lettersPerNumber(i),%22 letters.%22%0A%0A    print %22Total number of letters up to %22,finalNumber,%22: %22,runningTotal%0A%0AlettersForAllNumbersUpTo(1000)

fix bugs with fifteen/ten, still some remaining