I've a strange issue in python, the division is not performed correctly:
print pointB[1]
print pointA[1]
print pointB[0]
print pointA[0]
print (pointB[1]-pointA[1]) / (pointB[0]-pointA[0])
These are the results:
100
50
100
40
0
thanks
I've a strange issue in python, the division is not performed correctly:
print pointB[1]
print pointA[1]
print pointB[0]
print pointA[0]
print (pointB[1]-pointA[1]) / (pointB[0]-pointA[0])
These are the results:
100
50
100
40
0
thanks
This will be fixed in Python 3.0, for the time being you can use:
from __future__ import divison
and then use /
to get the result you desire.
>>> 5 / 2
2
>>> from __future__ import division
>>> 5 / 2
2.5
Since you are dividing two integers, you get the result as an integer.
Or, change one of the numbers to a float
.
>>> 5.0 / 2
2.5
This is how integer division works in python. Either use floats or convert to float in your calculation:
float(pointB[1]-pointA[1]) / (pointB[0]-pointA[0])
It is done correctly.
50/60 = 0
Maybe you are looking for 50.0/60.0 = 0.83333333333333337, you can cast your variables to float to get that:
print float(pointB[1]-pointA[1]) / (pointB[0]-pointA[0])