Created
June 30, 2020 04:51
-
-
Save fay-jai/f58588b237ef4923b49ad9a00afec0d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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