Daniel La Cour Daniel La Cour - 2 months ago 14
Python Question

Incorrect output from simplifying fraction

I have a simple code, written to simplify fractions in python. Putting in certain numbers (Such as shown in the code) give huge, and possibly incorrect values. Below is the code.

from fractions import Fraction

And it outputs:


Why does it do this, and how can I fix this?


I believe that you intended to use Fraction(36, 40). Notice the comma instead of the slash. What happens is that you input a division result instead of the numerator and denominator.

There are quite a few ways to init the Fraction. Take a look at the docs.