Устно отформатируйте число в Python

Как делают 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
8
задан Nietzche-jou 2 July 2010 в 06:52
поделиться

1 ответ

нет в ядре 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 не преобразуется в целое число точно, как и в вашем примере)

8
ответ дан 5 December 2019 в 18:56
поделиться
Другие вопросы по тегам:

Похожие вопросы: