Activity 01
Pair Programming: Closure Counter Builder
Pairs write an outer function returning an inner counter function that increments a captured variable. They test by creating multiple counters and calling them repeatedly, then print values to verify independent states. Pairs swap codes to debug and explain persistence.
Explain the concept of a closure and its practical applications.
Facilitation TipDuring Pair Programming: Closure Counter Builder, pair students so one writes while the other watches and questions the variable references before running the code.
What to look forPresent students with a Python code snippet featuring a nested function and a closure. Ask them to predict the output and explain why the inner function retains access to the outer function's variables. Review answers as a class.