defmake_converter(c,f):"""Connect c to f with constraints to convert from Celsius to Fahrenheit."""u,v,w,x,y=[connector()for_inrange(5)]multiplier(c,w,u)multiplier(v,x,u)adder(v,y,f)constant(w,9)constant(x,5)constant(y,32)
defmake_instance(cls):"""Return a new object instance, which is a dispatch dictionary."""defget_value(name):ifnameinattributes:returnattributes[name]else:value=cls['get'](name)returnbind_method(value,instance)defset_value(name,value):attributes[name]=valueattributes={}instance={'get':get_value,'set':set_value}returninstancedefbind_method(value,instance):"""Return a bound method if value is callable, or value otherwise."""ifcallable(value):defmethod(*args):returnvalue(instance,*args)returnmethodelse:returnvaluedefmake_class(attributes,base_class=None):"""Return a new class, which is a dispatch dictionary."""defget_value(name):ifnameinattributes:returnattributes[name]elifbase_classisnotNone:returnbase_class['get'](name)defset_value(name,value):attributes[name]=valuedefnew(*args):returninit_instance(cls,*args)cls={'get':get_value,'set':set_value,'new':new}returnclsdefinit_instance(cls,*args):"""Return a new object with type cls, initialized with args."""instance=make_instance(cls)init=cls['get']('__init__')ifinit:init(instance,*args)returninstancedefmake_account_class():"""Return the Account class, which has deposit and withdraw methods."""def__init__(self,account_holder):self['set']('holder',account_holder)self['set']('balance',0)defdeposit(self,amount):"""Increase the account balance by amount and return the new balance."""new_balance=self['get']('balance')+amountself['set']('balance',new_balance)returnself['get']('balance')defwithdraw(self,amount):"""Decrease the account balance by amount and return the new balance."""balance=self['get']('balance')ifamount>balance:return'Insufficient funds'self['set']('balance',balance-amount)returnself['get']('balance')returnmake_class({'__init__':__init__,'deposit':deposit,'withdraw':withdraw,'interest':0.02})Account=make_account_class()jim_acct=Account['new']('Jim')jim_acct['get']('holder')jim_acct['get']('deposit')(20)jim_acct['set']('interest',0.04)