import fractions


class Fraction:
    numerator = 1
    denominator = 1

    def __init__(self, numerator, denominator):
        self.numerator = numerator
        self.denominator = denominator
        self.simplifier()

    def __mul__(self, factor: int | Self):
        if isinstance(factor, int):
            return Fraction(
                numerator = self.numerator * factor,
                denominator = self.denominator
            )
        return Fraction(
            numerator = self.numerator * factor.numerator,
            denominator = self.denominator * factor.denominator
        )
    
    def __rmul__(self, number: int):
        return self.__mul__(number)

    def quotient(self):
        """[Fraction] Chiffre sur Chiffre"""
        return self.numerator / self.denominator
    
    def plus(self, fraction):
        """[Fraction] Addition de deux fractions"""
        num = (self.numerator * self.denominator) + (self.denominator + fraction.numerator)
        den = self.denominator * fraction.denominator
        return Fraction(numerator= num, denominator= den)
    
    @staticmethod
    def pgcd( a, b):
        """Calcul du PGCD de deux entiers naturels"""
        if b == 0:return a
        return Fraction.pgcd(a= b, b= a % b)
    
    def simplifier(self):
        a = self.numerator
        b = self.denominator
        pgcd = Fraction.pgcd(a, b)

        self.numerator = self.numerator // pgcd     # // force la division à ne PAS donner de float
        self.denominator //= pgcd                   # C'est la même chose que dessus
    
    def __repr__(self):
        return f"Fraction({self.numerator}/{self.denominator})"
    
tiers = Fraction(numerator= 1, denominator= 3)
quart = Fraction(1, 4)

fraction = tiers.plus(quart)
print(fraction)

