Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def make_account(balance):
def withdraw(amount):
nonlocal balance
if balance > amount:
balance -= amount
return balance
def deposit(amount):
nonlocal balance
balance += amount
return balance
return { "withdraw": withdraw, "deposit": deposit }
my_account = make_account(1000)
my_account["deposit"](500) # returns 1500
my_account["withdraw"](200) # returns 1300
your_account = make_account(2000)
your_account["deposit"](100) # returns 2100
your_account["withdraw"](200) # returns 1900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.