Skip to content

Instantly share code, notes, and snippets.

@fay-jai
Created June 30, 2020 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fay-jai/f58588b237ef4923b49ad9a00afec0d5 to your computer and use it in GitHub Desktop.
Save fay-jai/f58588b237ef4923b49ad9a00afec0d5 to your computer and use it in GitHub Desktop.
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