https://projecteuler.net/problem=17
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?
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.
First write a number_to_words(n) function that takes an integer n between 1 and 1000 inclusive and returns a list of words for the number as described above
In [3]:
x = list(one, two, three)
x
In [ ]:
def number_to_words(n):
"""Given a number n between 1-1000 inclusive return a list of words for the number."""
Now write a set of assert tests for your number_to_words function that verifies that it is working as expected.
In [ ]:
# YOUR CODE HERE
raise NotImplementedError()
In [ ]:
assert True # use this for grading the number_to_words tests.
Now define a count_letters(n) that returns the number of letters used to write out the words for all of the the numbers 1 to n inclusive.
In [ ]:
def count_letters(n):
"""Count the number of letters used to write out the words for 1-n inclusive."""
# YOUR CODE HERE
raise NotImplementedError()
Now write a set of assert tests for your count_letters function that verifies that it is working as expected.
In [ ]:
# YOUR CODE HERE
raise NotImplementedError()
In [ ]:
assert True # use this for grading the count_letters tests.
Finally used your count_letters function to solve the original question.
In [ ]:
# YOUR CODE HERE
raise NotImplementedError()
In [ ]:
assert True # use this for gradig the answer to the original question.