def __add__(self, other):
     common_multiple = rational_math.lcm(self.q, other.q)
     self_multiplier = common_multiple / self.q
     other_multiplier = common_multiple / other.q
     return Fraction(self.p * self_multiplier + other.p * other_multiplier,
                     common_multiple)
Exemplo n.º 2
0
 def test_lcm_1_2(self):
     self.assertEqual(rational_math.lcm(1, 2), 2)
 def __add__(self, other):
     common_multiple = rational_math.lcm(self.q, other.q)
     self_multiplier = common_multiple / self.q
     other_multiplier = common_multiple / other.q
     return Fraction(self.p * self_multiplier +
                     other.p * other_multiplier, common_multiple)