我写了一个crule1.py,如下所示。Python的一个奇怪的计算结果
def exp_rule1 (mu1, h, alpha):
return h**2/(4*mu1**2)
然后我在解释器中运行它。我得到
Python 2.7.6 |Anaconda 1.9.1 (64-bit)| (default, Nov 11 2013, 10:49:15) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Imported NumPy 1.8.0, SciPy 0.13.3, Matplotlib 1.3.1
Type "scientific" for more details.
>>> import crul1 as c1
>>> c1.exp_rule1(1, 1, 0)
0
然后我将代码复制到解释器。结果是
>>> def exp_rule1 (mu1, h, alpha):
... return h**2/(4*mu1**2)
...
>>> exp_rule1(1, 1, 0)
0.25
这让我很困惑,我无法修复它。非常感谢您在此代码中指出问题。
这两个实例运行python 2? – M4rtini
定义“解释器”。你在'import cru1 as c1','c1.exp_rule1(1,1,0)'line的同一个shell中运行第二个? – delnan
是的,我运行相同的shell。该版本是Python 2.7 –