几个小时前我发布了这个问题,但我想我删除了它!真的很抱歉......我正在研究Project Euler问题17.
虽然还有其他更明显的解决方案,但作为一种学习练习,我找到了想要使用递归解决问题的问题.我还希望某些代码片段以后可以在其他环境中使用.对于那些不熟悉的问题,问题描述本身位于代码顶部的docstring中.
这是有问题的代码:
"""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 …Run Code Online (Sandbox Code Playgroud) python ×1