+

Python | sympy.Rational () method

Using the sympy.Rational() method, we can find the rational form of any floating point value that is passed as a parameter to sympy.Rational () .

Syntax: sympy.Rational (val)
Return: Return Rational form of float value.

Example # 1:
In this example, we can see that with sympy.Rational () we can find the rational form of any floating point value that is passed as parameters.

Output:

1/5

Example # 2:

# import sympy

from sympy import *

 
# Using sympy.Rational () method

gfg = Rational ( 0.2 )

 

print (gfg)

# import sympy

from sympy import *

 
# Using the sympy.Rational () method

gfg = Rational ( 0.12 )

 

print (gfg)

Logout:

12/100

Get Solution for free from DataCamp guru