def fun332(x):
if not x:
return 'Zero'
x = str(x)
within_twenty = ['Zero','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten',
'Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']
tens = ['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']
def prefix(n,unit='',space=' '):
n = str(int(n))
if n == '0':
return ''
if len(n) == 1:
return '%s%s%s'%(space,within_twenty[int(n)],unit)
if len(n) == 2:
if int(n) < 20:
return '%s%s%s'%(space,within_twenty[int(n)],unit)
elif int(n) >= 20 and not int(n)%10:
return '%s%s%s'%(space,tens[int(n[0])-2],unit)
else:
return '%s%s %s%s'%(space,tens[int(n[0])-2],within_twenty[int(n[1])],unit)
if len(n) == 3:
if not int(n)%100:
return '%s%s Hundred%s'%(space,within_twenty[int(n[0])],unit)
elif int(n[1:2]) >= 20 and not int(n[1:2])%10:
return '%s%s Hundred %s%s'%(space,within_twenty[int(str(n)[0])],tens[int(n[1])-2],unit)
else:
return '%s%s Hundred %s %s%s'%(space,within_twenty[int(str(n)[0])],tens[int(n[1])-2],within_twenty[int(n[2])],unit)
if len(x) <= 3:
return prefix(x)
elif len(x) <= 6:
return '%s%s'%(prefix(x[:-3],' Thousand',space=''),prefix(x[-3:]))
elif len(x) <= 9:
return '%s%s%s'%(prefix(x[:-6],' Million',space=''),prefix(x[-6:-3],' Thousand'),prefix(x[-3:]))
else:
return '%s%s%s%s'%(prefix(x[:-9],' Billion',space=''),prefix(x[-9:-6],' Million'),prefix(x[-6:-3],' Thousand'),prefix(x[-3:]))