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.


Python
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)
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Binding and Scoping Questions: