Wie Pythonistas eine Zahl als Worte drucken zu tun, wie das Äquivalent des Common Lisp-Code:forma Verbal eine Zahl in Python
[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
Excellent handhaben kann - (? C) Ich habe bemerkt, tatsächlich das, aber es ist ein Fehler, wie Python behandelt die exponentiellen ausdruck: 'int (1e25)' erzeugt '1000000000000000000905969664L' und' 1 * 10 ** 25' erzeugt '1000000000000000000000000000L'. Seltsam? –
Nicht sonderlich seltsam. '1e25' ist" mache den Gleitkommawert am nächsten zu 10^25 ", und' 1 * 10 ** 25' sagt "multipliziere 1 mit dem Ergebnis, dass 10 selbst 25 Mal multipliziert wird". Gleitkommaarithmetik mit fester Breite (auf einem Computer) ist mathematisch nicht präzise, während Integer in neueren Versionen von Python willkürlich sind. – Ken
1e25 ist kein "exponentieller Ausdruck", sondern ein Fließkomma-Literal. Und eine Fließkommazahl in Python kann nicht genau 10 ** 25 darstellen (und das sollte keine große Überraschung sein, da 2 ** 84> 10 ** 25> 2 ** 83). – 6502