class Rational:
# constructor method
def __init__(self,n,d):
self._numerator = n
self._denominator = d
self.reduce()
def reduce(self):
pass
def add(self,f):
num = self._numerator * f._denominator + \
self._denominator * f._numerator
denom = self._denominator * f._denominator
return Rational(num,denom)
def __str__(self):
return str(self._numerator) + "/" + str(self._denominator)
r1 = Rational(5,10)
r2 = Rational(2,3)
print(r1)
print(r2)
5/10 2/3
r3 = r1.add(r2)
print(r3)
35/30
str(r3)
'35/30'