-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path017.py
More file actions
39 lines (35 loc) · 1.25 KB
/
017.py
File metadata and controls
39 lines (35 loc) · 1.25 KB
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
29
30
31
32
33
34
35
36
37
38
39
units=['','one','two','three','four','five','six','seven','eight','nine']
tenths=['','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']
ten=['ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
hundred='hundred'
e='and'
verb=True
soma=0
for i in range(1,1000):
h=i/100
d=(i-100*h)/10
u=i-100*h-10*d
if i<10:
if verb: print i, units[u]
soma += len(units[u])
elif i<20:
if verb: print i, ten[u]
soma += len(ten[u])
elif i<100:
if verb: print i, tenths[d], units[u]
soma += len(tenths[d]) + len(units[u])
else:
if d==0 and u==0:
if verb: print i, units[h], hundred
soma += len(units[h])+len(hundred)
elif d==0:
if verb: print i, units[h], hundred, e, units[u]
soma += len(units[h])+len(hundred)+len(e)+len(units[u])
elif d==1:
if verb: print i, units[h], hundred, e, ten[u]
soma += len(units[h])+len(hundred)+len(e)+len(ten[u])
else:
if verb: print i, units[h], hundred, e, tenths[d], units[u]
soma += len(units[h])+len(hundred)+len(e)+len(tenths[d])+len(units[u])
soma += len('onethousand')
print soma