Tell us what’s happening:
Can someone help me as to why my deposit function isn’t working? I think it is creating an object in the ledger but the console says otherwise.
Also, can someone tell me why balance is unbound when I check it at check_funds? I get an error saying cannot access local variable ‘balance’ where it is not associated with a value
Your code so far
class Category:
def __init__ (self, name):
self.name = name
self.ledger = []
self.balance = 0
def deposit(self, amount, description = ""):
self.balance += amount
self.ledger.append({'amount': amount, 'description': description})
def withdraw(self, amount, description = ""):
if self.check_funds(amount):
balance -= amount
self.ledger.append({'amount': amount, 'description': description})
return True
else:
return False
def check_funds(self, amount):
if (amount > self.balance):
return False
else:
return True
def create_spend_chart(categories):
pass
food = Category("Food")
food.withdraw(-5)
print(food.ledger)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App - Build a Budget App