-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem_17.py
31 lines (23 loc) · 903 Bytes
/
Problem_17.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
28
29
30
31
# Number letter counts
# Problem 17
# https://projecteuler.net/problem=17
# 2If 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?
#
#
# NOTE: Do not count spaces or hyphens.
# For example,
# 342 (three hundred and forty-two) contains 23 letters
# and 115 (one hundred and fifteen) contains 20 letters.
# The use of "and" when writing out numbers is in compliance with British usage.
# Answer: 21124.
# Need install modul 'num2words' - pip install num2words
from num2words import num2words as nn
def number_in_english(n):
return nn(n, lang='en')
count: int = 0
for i in range(1, 1001):
count += len(number_in_english(i).replace(' ', '').replace('-', ''))
print("Answer:", count)