- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigureToWords.py
More file actions
Latest commit
28 lines (24 loc) · 939 Bytes
/
Copy pathfigureToWords.py
File metadata and controls
28 lines (24 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
singleDigit= ['zero', 'one', 'two', 'three',
'four', 'five', 'six', 'seven', 'eight', 'nine']
doubleDigit= ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen',
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
tenMultiple= ['', '', 'twenty', 'thirty', 'forty',
'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
tenPower='hundred'
deffig2words(n: int) ->str:
length=len(str(n))
s=''
iflength==1:
returnsingleDigit[n].capitalize()
iflength==3:
s+=singleDigit[n//100]+' '+tenPower
n=n%100
ifn==0:
returns.capitalize()
else:
s+=' and '
ifn>9andn<20:
return (s+doubleDigit[n%10]).capitalize()
s+=tenMultiple[n//10]
returns.capitalize() ifn%10==0else (s+' '+singleDigit[n%10]).capitalize()
print(fig2words(50))