Horje
simplify fractions python Code Example
simplify fractions python
>>> from fractions import Fraction
>>> Fraction(98, 42)
Fraction(7, 3)
python simplify fraction
#From scratch

#Euclid's algorithm https://en.wikipedia.org/wiki/Greatest_common_divisor#Euclid's_algorithm
def gcd(a: int, b: int):
    fraction = (a, b)
    while fraction[0] != fraction[1]:
        maximum = max(fraction)
        minimum = max(fraction)
        fraction = (maximum - minimum, minimum)
    return fraction[0]

def simplify(a: int, b: int):
  divisor = gcd(a, b)
  return (a / divisor, b / divisor)




Python

Related
python execute bat file Code Example python execute bat file Code Example
print on two digit python format Code Example print on two digit python format Code Example
how to print numbers from 1 to 20 in python Code Example how to print numbers from 1 to 20 in python Code Example
dataframe rank groupby Code Example dataframe rank groupby Code Example
pandas rename Code Example pandas rename Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8