Take a look at this:
print 41063625 ** (1.0/3) # cube-root(41063625) = 345
print int(345.0)
print int(41063625 ** (1.0/3))
It outputs:
345.0
345
344
I was expecting the last line to be 345, since I was expecting int(41063625 ** (1.0/3)) to equal int(345.0) to in turn equal 345, as the other two outputs suggest. However, this is evidently not the case. Can anyone give me any insight as to what’s going on here?
Print (or rather
float.__str__) is rounding the output.The floating point representation for
41063625 ** (1.0/3)is less than 345, so when you take theintof it, you get 344 rather than 345.If you want the closest int, you could use round:
or, to get an
int: