PythiloLesson 2 of 8 · progress kept in this browser

Apply a repeated event only once

A queue may deliver an event more than once. Applying every delivery would double-count work, while marking an event before validating it can lose a legitimate change. An idempotency key identifies the logical operation. For this in-memory exercise, remember processed identifiers together with the current total, and leave both unchanged when validation fails.

seen = {"event-1"}
print("event-1" in seen)
Your task

Write apply_event(total, seen, event_id, amount). amount must have exactly type int; otherwise raise ValueError without changing seen. A new event adds amount and records its id in the supplied set. A duplicate returns total unchanged.