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)Think before coding
Validation happens before any mutation, so a failed event remains retryable. Duplicate delivery does not repeat its effect. Durable concurrent systems must store the id and effect atomically in a transaction. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
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.
The explanation opens here once every check passes.