"""
Exercise 1: fix the UnboundLocalError

The function below is meant to track a running total across calls using
a module-level global, but it's broken: calling it raises
UnboundLocalError instead of accumulating.

Fix ONLY the function body (you may add `global`, you may NOT change
the module-level `total = 0` line or the self-check).
"""

total = 0

def add_to_total(amount):
    # TODO: fix this function so it accumulates into the module-level
    # `total` instead of raising UnboundLocalError.
    total = total + amount
    return total


# --- self-check: do not modify below this line ---
r1 = add_to_total(10)
r2 = add_to_total(5)
r3 = add_to_total(-3)

ok = (r1, r2, r3, total) == (10, 15, 12, 12)
print(f"results: {(r1, r2, r3, total)}")
print("PASS" if ok else "FAIL")
