can anybody help me out with the particular situation where i am unable run my check_funds() function.![codesnippet|422x500]errorsnap|690x126
def withdraw(self,amount,description=''):
if self.check_funds(amount)==False:
self.ledger.append({'amount':-1*amount,'description':description})
return True
else:
return False
def get_balance(self):
total=0
for i in self.ledger:
total+=i['amount']
return total
def transfer(self,amount,b_category):
if self.check_funds(amount)==False:
self.ledger.append({'amount':-1*amount,'description':'Transfer to '+str(b_category.name_of())})
b_category.deposit(amount,'Transfer from '+self.name)
return True
else:
return False
def check_funds(self,amount):
balance=0
for i in self.ledger:
balance+=i['amount']
if balance<amount:
return True
else:
return False
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
May I ask how you did your transfer() method? Specifically the line that adds to the receiving ledger 'Transfer from [Source budget category]'? I'm not entirely sure how to add in the name of the Instance as a variable. Any help would be greatly appreciated!
see first all i have done is simply add to the ledger where amount is received and secondly remove the entry of ledger from where the amount was transferred
the transfer takes in the amount and the object where the sum is to be transferred.For your reference see the snippet below.
```def transfer(self,amount,b_category):
if self.check_funds(amount):
self.ledger.append({'amount':-1*amount,'description':'Transfer to '+str(b_category.name_of())})
b_category.deposit(amount,'Transfer from '+self.name)
return True
else:
return False```