pythonistas如何将数字作为单词打印,就像Common Lisp代码的等价物一样:
[3]> (format t "~r" 1e25)
nine septillion, nine hundred and ninety-nine sextillion, nine hundred and ninety-nine quintillion, seven hundred and seventy-eight quadrillion, one hundred and ninety-six trillion, three hundred and eight billion, three hundred and sixty-one million, two hundred and sixteen thousand
解决方法:
没有在python核心,但有第三方库num2words
>>> from num2words import num2words
>>> num2words(1e25)
'ten septillion, one billion, seventy-three million, seven hundred and forty-one thousand, eight hundred and twenty-four'
>>> num2words(10000000000000000000000000)
'ten septillion'
(请注意,1e25未精确转换为整数,在您的示例中均未转换为整数)