Created
August 30, 2017 21:19
-
-
Save edcrypt/f253822512c4e073fb5747695902fa5b to your computer and use it in GitHub Desktop.
Revisions
-
edcrypt created this gist
Aug 30, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ def Account(balance): ret = None while True: # receive message selector, *args = yield ret # dispatch if selector == 'withdraw': print('Got withdraw') new_balance = balance - args[0] if new_balance < 0: ret = 'NO LIMIT' else: balance = new_balance ret = balance elif selector == 'deposit': print('Got deposit') balance += args[0] ret = balance account = Account(100) # init... next(account) print(account.send(['withdraw', 7])) print(account.send(['deposit', 8]))