class utilities(object): def gcd(a, b): hi = max(abs(a), abs(b)) lo = min(abs(a), abs(b)) div = lo while not (hi % div == 0 and lo % div == 0): div -= 1 return div gcd = staticmethod(gcd) class fraction(object): def __init__(self, num, den): self.num = num / utilities.gcd(num, den) self.den = den / utilities.gcd(num, den) def __str__(self): return str(self.num) + "/" + str(self.den) def add(self, other): return fraction(self.num * other.den + self.den * other.num, self.den * other.den) def sum(a, b): return fraction(a.num * b.den + a.den * b.num, a.den * b.den)