Next / Previous / Contents / Shipman's homepage

3.7. Rational.__mul__(): Implement multiplication

Here's the formula for multiplying two fractions:

rational.py
    def __mul__ ( self, other ):
        """Implement multiplication.
        """
        return  Rational ( self.n * other.n, self.d * other.d )