from fractions import Fraction value = 4.2 print(Fraction(value).limit_denominator())