Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Fractions Addition by Orthomonalus
from fractions import Fraction
def add_fractions(fracts):
result = sum(Fraction(*f) for f in fracts)
integer_part, remainder = divmod(result, 1)
if not remainder:
return integer_part
if not integer_part:
return str(remainder)
return f"{integer_part} and {remainder}"
if __name__ == '__main__':
print("Example:")
print(add_fractions(((2, 3), (2, 3))))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert add_fractions(((2, 3), (2, 3))) == "1 and 1/3"
assert add_fractions(((1, 3), (1, 3))) == "2/3"
assert add_fractions(((1, 3), (1, 3), (1, 3))) == 1
print("Coding complete? Click 'Check' to earn cool rewards!")
Feb. 16, 2026
Comments: