我寫了一個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 –