Division in Python < 3 works differently from what you may expect if you are used to for instance Matlab. So from a standard Python console you will get this (dividing integers results in an integer):
>>> 1/2
0
This has been changed in Python 3. To get the new behaviour put
from __future__ import division
above all the other imports in your script. Alternatively you could force floating point behaviour as follows:
>>> 1./2.
0.5
The reason why your code works in the Spyder console is because that already does the above import automatically.