A monitoring script maintains separate event counters for two sensors using the Python code below. Execute the final three assignments in order. Find first, second, and third, giving each as a unitless integer to zero decimal places.
def make_counter(start): count = start def advance(step): nonlocal count count = count + step return count return advance left = make_counter(10) right = make_counter(30) def run(counter): count = 200 return counter(3) first = run(left) second = left(4) third = right(2)
Unlock full course notes by signing up
Lookup after a module update
A drawing application uses integer scale factors. Execute the following Python statements in order and complete the table with the exact unitless integer printed beside each label.
Distinguishing scope vocabulary
You are documenting nested functions in a programming language. Match each term to its description, distinguishing name lookup, competing declarations, retained environments, and variable occurrences not bound within a function expression.
One program under two scoping rules
The program below is written in Python syntax. Assume every assignment or parameter inside a function creates a new local binding for that function, and that the module binding x = 1 never changes.
Each call is made separately from the module level. Fill in the integer value returned by each call when the free name x in get is resolved by lexical scope, and again when a hypothetical interpreter resolves it by dynamic scope, using the most recent active binding of x on the call stack.