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.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs