How would you write a number (integer) using English words? Here is one way, and to keep it simple let's just use numbers from 1 to 999.
# write a number from 1 to 999 in English words
ones = ["", "one ","two ","three ","four ", "five ",
"six ","seven ","eight ","nine "]
tens = ["ten ","eleven ","twelve ","thirteen ", "fourteen ",
"fifteen ","sixteen ","seventeen ","eighteen ","nineteen "]
twenties = ["","","twenty ","thirty ","forty ",
"fifty ","sixty ","seventy ","eighty ","ninety "]
# your test number between 1 and 999
n = 123
# separate into ones, tens/twenties, hundreds
b1 = n % 10
b2 = (n % 100)//10
b3 = (n % 1000)//100
print b1, b2, b3 # test, for n = 123 should show 3 2 1
# start with an empty string to build up
nw = ""
# no tens/twenties
if b2 == 0:
nw = ones[b1] + nw
# we have tens
elif b2 == 1:
nw = tens[b1] + nw
# we have twenties etc.
elif b2 > 1:
nw = twenties[b2] + ones[b1] + nw
# we have hundreds
if b3 > 0:
nw = ones[b3] + "hundred " + nw
print nw # test 123 --> one hundred twenty three