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 核心中没有,但有 3rd 方库 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 并未精确转换为整数)
https://stackoverflow.com/questions/3158132/