Input: d = 2.5 Output: 5/2 Explanation: 5/2 gives 2.5 which is the reduced form of any fraction that gives 2.5 Input: d = 1.5 Output: 3/2
Python as_integer_ratio () Function:
Returns a pair of integers whose ratio is exactly equal to the original floating point value and has a positive denominator.
float. as_integer_ratio ()
Tupple (a pair of integers)
Raises OverflowError on infinities and a ValueError on NaNs.
In Python, we have a built-in function as_integer_ratio (), that prints the reduced fractional form of any given rational number d. We need to store this in any variable and then print the 0th index and 1st index of the stored fraction.