Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
fractions.Fraction solution in Clear category for Fractions Addition by David_Jones
from fractions import Fraction
def add_fractions(fracts):
result = sum(Fraction(*fract) for fract in fracts)
quotient, remainder = divmod(result.numerator, result.denominator)
if not quotient:
return f'{remainder}/{result.denominator}'
if not remainder:
return quotient
return f'{quotient} and {remainder}/{result.denominator}'
June 13, 2019