Given a rational number d, print the reduced fraction which gives d.
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
as_integer_ratio() function Python:
Returns a pair of integers whose ratio is exactly equal to the original float and with a positive denominator.
Tupple (a pair of integers)
Raises OverflowError on infinities and a ValueError on NaNs.
In Python we have an inbuilt function as_integer_ratio() which prints the reduced fraction form of any given rational number d. We need to store that in any variable and then print the 0th index and 1st index of the stored fraction.
5 / 2
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Maximum rational number (or fraction) from an array
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- Product of given N fractions in reduced form
- Python | sympy.Rational() method
- Largest proper fraction with sum of numerator and denominator equal to a given number
- First occurrence of a digit in a given fraction
- Find N fractions that sum upto a given fraction N/D
- Max count of unique ratio/fraction pairs in given arrays
- Convert given Decimal number into an irreducible Fraction
- Fraction module in Python
- Binary Search for Rational Numbers without using floating point arithmetic
- Find max of two Rational numbers
- Find LCM of rational numbers
- N-th term of George Cantor set of rational numbers
- Greedy Algorithm for Egyptian Fraction
- Convert decimal fraction to binary number
- Print first N terms of series (0.25, 0.5, 0.75, ...) in fraction representation
- Find the Nth digit in the proper fraction of two numbers
- Mahotas - Fraction of zeros in image
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.