from fractions import Fraction total = 5 * 5 * 4 * 3 ending_zero = 5 * 4 * 3 ending_five = 4 * 4 * 3 divisible = ending_zero + ending_five intersection = 4 * 3 + 4 * 3 result = {"total": total, "divisible": divisible, "p_divisible": str(Fraction(divisible, total)), "p_first_one_given_divisible": str(Fraction(intersection, divisible))} import json print(json.dumps(result, ensure_ascii=False, sort_keys=True))