from fractions import Fraction fence = Fraction(120) x = fence / 4 y = fence - 2 * x area = x * y assert 2 * x + y == fence and x >= 0 and y >= 0 result = {"x_m": str(x), "y_m": str(y), "area_m2": str(area)} import json print(json.dumps(result, ensure_ascii=False, sort_keys=True))