This code outputs different values for Python 3 and Python 2, how to get same result for both?

44 Views Asked by At
def mod_inverse_iterative(a, b):
    x, y, u, v = 0, 1, 1, 0
    while a != 0:
        q  = b / a
        r=b % a
        m = x - u * q
        n=y - v * q
        b, a, x, y, u, v = a, r, u, v, m, n
    return b, x, y

print(mod_inverse_iterative(66185,4080))

output python 2: (5, -275, 4461) output python 3: (5, -1376.9583960493067, 11238.87370164165)

1

There are 1 best solutions below

0
On

As someone already said in comments is due to python division. Check this link if you need more hints to port from python 2 to 3.

Also check this link from python docs.

So, just change q = b / a for q = b // a