Am working on the python BudgetApp and am looking at the TRANSFER process:
accepts an amount and another budget category as arguments. The method should add a withdrawal with the amount and the description "Transfer to [Destination Budget Category]". The method should then add a deposit to the other budget category with the amount and the description "Transfer from [Source Budget Category]". If there are not enough funds, nothing should be added to either ledgers. This method should return True if the transfer took place, and False otherwise.
I am 90% certain I am on the right track with the code (all of the code so far is):
class Category():
def __init__(self, name):
self.name=name
self.ledger=list()
self.runningBalance=int()
def deposit(self,amount,description=""):
self.ledger.append({"amount":amount,"description":description})
self.runningBalance=self.runningBalance+amount
print(self.name, "deposit:", self.ledger)
def withdraw(self, amount, description=""):
# amount passed in should be stored in the ledger as a negative number. If there are not enough funds, nothing should be added to the ledger. This method should return True if the withdrawal took place, and False otherwise.
if self.runningBalance >= amount:
self.ledger.append({"amount":amount*-1,"description":description[0]})
self.runningBalance=self.runningBalance-amount
print(self.name, "withdrawl:", self.ledger)
return True
else:
return False
def get_balance(self):
#returns the current balance of the budget category based on the deposits and withdrawals that have occurred.
return (self.runningBalance*10)/10
def transfer(self, amount, destination):
#accepts an amount and another budget category as arguments. The method should add a withdrawal with the amount and the description "Transfer to [Destination Budget Category]". The method should then add a deposit to the other budget category with the amount and the description "Transfer from [Source Budget Category]". If there are not enough funds, nothing should be added to either ledgers. This method should return True if the transfer took place, and False otherwise.
if self.runningBalance >= amount:
print(amount)
self.ledger.append({"amount":amount*-1,"description": "Transfer to " + destination})
destination.deposit(amount, "Transfer from "+ self.name)
self.runningBalance=self.runningBalance-amount
print(self.name, "transfer:", self.ledger)
def check_funds(self, amount):
#accepts an amount as an argument. It returns False if the amount is less than the balance of the budget category and returns True otherwise. This method should be used by both the withdraw method and transfer method.
print(amount)
def create_spend_chart(categories):
return
but I am getting the error:
Traceback (most recent call last):
File "main.py", line 13, in <module>
food.transfer(50, clothing)
File "/home/runner/fcc-budget-app/budget.py", line 36, in transfer
self.ledger.append({"amount":amount*-1,"description": "Transfer to " + destination})
TypeError: can only concatenate str (not "Category") to str
am fairly sure it is how I am accessing the value of destination but, having looked at other code for the same example I cannot get mine to work. Maybe I have missed something further up…
thanks as always