0

I was working on permutations and came across this difference in python and python3.

PYTHON:

Python 2.7.11+ (default, Jun  2 2016, 19:34:15)
>>> x=2432902008176639999
>>> y=121645100408832000
>>> q=x/y
>>> q
19

Now PYTHON3 :

Python 3.4.4 (default, Apr 17 2016, 16:02:33)
>>> x=2432902008176639999
>>> y=121645100408832000
>>> q=x/y
>>> q
20.0

Can somebody explain this and how to get same results ?

techcomp
  • 370
  • 3
  • 16
  • 1
    python3.x is using true division instead of floor division. Eitehr use `//` if you want the python2.x behavior or `from __future__ import true_division` if you want the python3.x behavior. – mgilson Jul 28 '16 at 06:37
  • See this: http://stackoverflow.com/documentation/python/809/compatibility-between-python-3-and-python-2/2797/integer-division – DeepSpace Jul 28 '16 at 06:38
  • The exact result is very very slightly less than 20. Python 2 floor-divides, and the floor of the exact value is 19. Python 3 produces a float, and the closest float to the exact value is 20.0. – user2357112 Jul 28 '16 at 06:46

0 Answers0