Code for add function:
def __add__(self, rightSide):
"""
Purpose: Adds two fractions together to get the sum
:param rightSide: Placeholder for second fraction to be calculated with original fraction
:return: None
"""
numer = self.__numerator * rightSide.getDenominator() + self.__denominator * rightSide.getNumerator()
denom = self.__denominator * rightSide.getDenominator()
new_frac = Fraction(numer, denom)
print(new_frac)
Driver code:
print(f'{frac_a} + {frac_b} = ', frac_a + frac_b)
Output:
16/15
2/5 + 2/3 = None
When I have frac_a at the end of the formatting code, it will print 2/5 after the equal sign. But when I add the operator and frac_b, it outputs what js shown.