A function tries to increment a global counter, but instead of updating it, Python throws an UnboundLocalError saying the variable is referenced before assignment.
If you assign to a variable ANYWHERE inside a function, Python treats it as a local variable for the ENTIRE function body — even on lines before the assignment. So trying to read a global variable and then reassign it in the same function without declaring 'global' first causes this error.