我們如何在python中以指定的精度計算立方體根?我們如何在python中以指定的精度計算立方體根?
我想用小數類,這和我的編譯器是Python 2.5的
我用這樣的嘗試:
>>> from decimal import *
>>> x=Decimal("10")
>>> print x**(Decimal("1.0")/3)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
print x**(Decimal("1.0")/3)
File "C:\Python25\lib\decimal.py", line 1752, in __pow__
return context._raise_error(InvalidOperation, 'x ** (non-integer)')
File "C:\Python25\lib\decimal.py", line 2325, in _raise_error
raise error, explanation
InvalidOperation: x ** (non-integer)
>>>
這是工作pyth 2.6及以後而不是在pyth 2.5 ?任何解決方案?
函數的參數是'n',但應該是'x' – 2011-03-04 01:59:05
可以在Python 2.6.1(r261:67515,2010年6月24日,21:47:49)上運行 [GCC 4.2.1(Apple Inc. build 5646)]達爾文' – Zach 2011-03-04 02:37:08
是的,我已經提到,但不能在pyth 2.5中工作。 – Quixotic 2011-03-04 02:54:06