Spoken Numbers by recursive

_=lambda n,S:n and _(n/M,S[1:])+(Z[n%M/C]+"hundred ")*(n%M>99)+(n%C>19and p("twen thir fo"+R,"ty")[n%C/10-2]+Z[n%10]or Z[n%C])+S[0]*(n%M>0)or""
p=lambda a,b="":[i+b+" "for i in a.split()]
R="r fif six seven eigh nine"
M=1000
C=100
Z=[""]+p("one two three four five%st nine ten eleven twelve"%R[5:20])+p("thir fou"+R,"teen")
while 1:print _(input(),["","thousand "]+p("m b","illion"))[:-1]

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page