0

Can someone help me figure out why the same simple calculation gets different answers in python 2 and 3? The expression is ​(0.2**(-2)-1)**(1/2).

When I use python 2 in a Canopy IDE, I get 1.

When I use python 3 in google colab, I get 4.98.

In both cases I am literally running exactly the above expression. Any ideas?

1 Answers1

3

Integer division works differently in Python 2 and 3.

For example (1/2) will return

0 in Python 2, and

0.5 (a float) in Python 3.

blackraven
  • 5,284
  • 7
  • 19
  • 45
bananafish
  • 2,877
  • 20
  • 29