fractions http://docs.python.org/2/library/fractions.html http://docs.python.org/2/library/fractions.html http://docs.python.org/2/library/fractions.html code for doing this is part of the standard library fractions.Fraction http://docs.python.org/2/library/fractions.html