-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy path017-NumberLetterCounts.py
27 lines (22 loc) · 1005 Bytes
/
017-NumberLetterCounts.py
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
# If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
teens = ["", "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 donustur(n):
if(n<20):
return(teens[n])
elif(n<100):
return(tens[int(n/10)] + teens[n%10])
elif(n<1000):
if(n%100==0):
return(teens[int(n/100)]+"hundred")
else:
return(teens[int(n/100)]+"hundred"+"and"+donustur(n%100))
else:
return("onethousand")
sonuc = 0
for i in range(1,1001):
sonuc += len(donustur(i))
print(sonuc)