2013-06-24

Python: Compute Exact Fractions

# -*- coding: utf-8 -*-

import fractions

print( fractions.Fraction(5,100)) # 1/20
print( fractions.Fraction(4,100)) # 1/25
print( fractions.Fraction(3,100)) # 3/100
print( fractions.Fraction(2,100)) # 1/50

Note that Mathematica had this feature, transparently, since 1990.

In Mathematica, any exact number are computed exactly. Number without a decimal dot are exact.