runtime
145 / 500
question 145 Advanced Functions & Recursion · medium

Notify only when the status changes

An order tracker receives the same status many times (packed, packed, shipped…) and should message the customer only when it changes. make_change_detector() returns a function changed(value) for that, but calling it stops with UnboundLocalError. Fix it so that changed returns True when the value differs from the one passed on the previous call, and False when it is the same. The first call always counts as a change, whatever the value, including None.

Functionmake_change_detector()
Returnsa function changed(value)
changed(value)True on the first call and whenever value differs from the previous call's value; otherwise False
Ruleseach detector remembers only its own values

Loading your progress…

Notify only when the status changes — Python practice · Runtime