In Python 3,
y
is 4.20.
In Python 2, it is 4.00 indeed, so I assume you're using that version. And there is the cause: in Python 2, division between two integers returns an integer as well, whereas you actually want a floating-point number as result. (In Python 3, division is floating-point division by default and
//
does integer division)
There are two possible solutions to fix this:
One way is to make all your initial variables floats, like this:
s = 18.0
x = 0.000
g = 0.0
a = -1.0
Now all divisions (e.g.
a / 10
) are
float / int
divisions, which result in a float.
Another option, which does not require the above, is to tell Python to use floating-point division in all cases, by adding this line to the top of your code file:
from __future__ import division