Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Fraction with divmod solution in Clear category for Fractions Addition by martin_b
from fractions import Fraction
def add_fractions(fracts):
r = sum(Fraction(*f) for f in fracts)
w, p = divmod(r.numerator, r.denominator)
if w == 0:
return f"{p}/{r.denominator}"
elif p == 0:
return w
return f"{w} and {p}/{r.denominator}"
June 3, 2018
Comments: