How to do floating point computation in python ?
for j in range(10 , 50):
print "(10/(j+1)) is %f " % (10/(j+1))
Why is the output all 0s ?
j must be an integer , but I need the floating result .
thanks
In Python2, / will truncate the quotient of two integers into an integer,
you can either do
for j in range(10 , 50):
print "(10/(j+1)) is %f " % (10.0/(j+1))
or not to truncate globally, just as Python3 does
from __future__ import division
for j in range(10 , 50):
print "(10/(j+1)) is %f " % (10/(j+1))