Shared Cells Across Sibling Closures

def make_account(balance):
    def deposit(amount):
        nonlocal balance
        balance += amount
        return balance

    def withdraw(amount):
        nonlocal balance
        balance -= amount
        return balance

    def get_balance():
        return balance

    return deposit, withdraw, get_balance

dep1, wd1, bal1 = make_account(100)
dep2, wd2, bal2 = make_account(100)

dep1(50)
wd1(20)

Select all that apply.

A

Removing nonlocal balance from deposit would make dep1(50) raise UnboundLocalError, because balance += amount would make balance local to deposit

B

deposit, withdraw, and get_balance returned by the same make_account call all close over the same cell for balance, so wd1(20) is visible to bal1()

C

bal1() now returns 130

D

bal2() also returns 130, because every closure produced by make_account shares one cell for balance