문제

I have a script with the following statements:

Me = 5.97219E+24
Ms = 1.9891E+30
ae = 149597887155
r = ae*((Me/Ms)**(2/5))

After running the script, the variable r has the same value 149597887155 which is the same as ae. This is obviously not the value I would expect after evaluating the expression.

I tried restarting my computer, starting a new Python interpreter and even installing another Python distribution. It is the same result in every case.

Currently, I am using Anaconda with Python 2.7 and Spyder as editor.

Curiously, when I copy and paste the statements into the interpreter directly, they are evaluated correctly.

Does this sound familiar to anybody? Is there a known cause for this?

도움이 되었습니까?

해결책

Well in Python 2.7, 2/5 is an integer division, resulting in 0. Anything powered by 0 is 1, which means that the final result for r is ae*1.

In Python 3.3, 2/5 results in 0.4 and probably gives the result you expect.

Regarding the difference in console only: I have no differences.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top