I am working on the Budget app-project and can’t seem to get my head around some details of the methods:
The Transfer-method should draw an amount from category A and deposit the amount in category B. I want to do this by calling the withdraw and deposit methods in a method ‘transfer’, but I can’t find out how to assign two different categories in this method (category A to withdraw and category B to deposit).
Can anyone explain how this would work?
code so far:
class Category :
def __init__ (self, categoryname) :
self.categoryname = categoryname
self.ledger = list[]
self.balance = 0
def deposit(self, amount, description = "") :
self.ledger.append({"amount" = amount, "description" = description})
self.balance += amount
def withdraw(self, amount, description = "") :
if check_funds = True :
self.ledger.append({"amount" = -amount, "description" = description})
self.balance -= amount
return True
else :
return False
def transfer (self, amount, categoryname) :
if check_funds = True :
# call withdraw method
self.withdraw()
return "Transfer to " , categoryname
# call deposit method
self.deposit()
return "Transfer from " , categoryname
return True
else:
return False
def check_funds(self, amount) :
if amount > self.balance :
return False
else :
return True