fraction is a Python module that is designed for fractional values numerator/denominator
Easy to install
$ python -m pip install Fraction
>>> from fraction import Fraction
>>> f1 = Fraction()
>>> print(Fraction('1/2', '1/4'))
2/1
>>> print(Fraction('1.2'))
6/5
>>> print(Fraction('1.22/6'))
61/300
>>> f = Fraction.fromdecimal(1.3, rec='3')
>>> print(f)
4/3
>>> f = Fraction.fromdecimal(24.5067, rec='067')
>>> print(f)
122411/4995
>>> a = Fraction('3/10')
>>> b = Fraction('1/2')
# Get numerator/denominator
>>> a.numerator, a.denominator
(3, 10)
>>> recip_a = Fraction.reciprocal(a)
>>> recip_a.numerator, recip_a.denominator
(10, 3)
>>> sum_ab = a + b
>>> sum_ab.numerator, sum_ab.denominator
(4, 5)
>>> diff_ab = a - b
>>> diff_ab.numerator, diff_ab.denominator
(-1, 5)
>>> mul_ab = a * b
>>> mul_ab.numerator, mul_ab.denominator
(3, 20)
>>> div_ab = a / b
>>> div_ab.numerator, div_ab.denominator
(3, 5)
>>> a < b
True
>>> a == Fraction(7, 10)
False
>>> a = Fraction('1/3')
>>> a.todecimal(decplaces=5)
'0.33333'
>>> a = Fraction()
>>> print a
0/1
>>> a
Fraction: 0/1