def numToEng(n): m =list(str(n)) a = { '0':'zero','1':'one','2':'tow','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine'} b = {'10':'ten','11':'eleven','12': 'twelve','13': 'therteen','14': 'fourteen','15': 'fifteen' ,'16':'sixteen' ,'17':'seventeen', '18':'eighteen','19': 'nineteen'} c = { '2': 'twenty','3': 'thirty', '4': 'forty' ,'5': 'fifty' ,'6':'sixty' ,'7': 'seventy' ,'8':'eighty','9': 'ninety'} def anum(m): return a.get(''.join(m)) def bnum(m): if n<20 or int(''.join(m))<20: return b.get(''.join(m)) else: if m[1] is '0': return c.get(m[0]) if m[1] is not '0': return c.get(m[0])+'-'+anum(m[1]) def cnum(m): rr = int(''.join(m)) if rr in [100,200,300,400,500,600,700,800,900]: return a.get(m[0])+' hundred' elif m[1]=='0': return str(a.get(m[0])+' hundred '+a.get(m[2])) else: return str(a.get(m[0])+' hundred '+ bnum(m[1:3])) if len(m)==1: return anum(m) elif len(m)==2: return bnum(m) elif len(m)==3: return cnum(m)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter