Dan Dan - 9 months ago 60
Python Question

I'm making mistakes dividing large numbers

I am trying to write a program in python 2.7 that will first see if a number divides the other evenly, and if it does get the result of the division.

However, I am getting some interesting results when I use large numbers.

Currently I am using:

from __future__ import division
import math
if a/b==math.trunc(a/b):
print 'True' #to quickly see if the if loop was invoked

When I run this I get:


But 82348972389472433334783 is clearly not even.

Any help would be appreciated.

wim wim

That's a crazy way to do it. Just use the remainder operator.

if a % b == 0:
    # then b divides a evenly
    quotient = a // b