这似乎是一个重复的问题,也许确实如此,但我检查了许多其他来源,但似乎没有一个解决方案有效。我要计算的数字是 999,999^999,999,而且它毫无意义地大,但我已经尝试了一段时间了。我想将结果写入文本文件。我通常会收到溢出错误,在尝试解决另一个问题后,我开始收到不同的溢出消息。有什么办法可以计算出这个数字吗?如果python不能做到这一点,还有别的吗?
我此时的代码:
from decimal import Decimal
#Attempt 2 (Attempt 1 was just print(999999**999999))
a = Decimal(999999**999)
a = a**(2) #Not close enough. 2.0002895717 would be perfect, but that would cause another Overflow: "OverflowError: int too large to convert to float"
print(a)
open("number.txt","x").write(str(a))
#Attempt 3, I tried breaking down the power into it's square root, and then that into it's square roots
massiveNumber = Decimal(999999**31.6227608)
massiveNumber = Decimal(massiveNumber**Decimal(31.6227608))
massiveNumber = Decimal(massiveNumber**Decimal(31.6227608))
massiveNumber = Decimal(massiveNumber**Decimal(31.6227608))
open("number.txt","w").write(str(massiveNumber))
错误:
Traceback (most recent call last):
File "unknowablenumber.py", line 13, in <module>
massiveNumber = Decimal(massiveNumber**Decimal(31.6227608))
decimal.Overflow: [<class 'decimal.Overflow'>]