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.
scale = 4 def read_scale(): return scale def render_preview(): scale = 11 return read_scale() print("A", read_scale()) scale = 7 print("B", read_scale()) print("C", render_preview())
Unlock full course notes by signing up
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.
Two counters and a misleading caller
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.
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.