Search code examples
pythonsympyprobability

Dealing with rationals in SymPy


>>> Rational((0.5*1/2)/(0.5*1/2+0.2))
2501999792983609/4503599627370496

So I want this to give me a fraction of 5/9, is it possible to get that in python?


Solution

  • You can either use nsimplify instead of Rational or else use the limit_denominator on the Rational:

    enter image description here