Hello everyone,
Here is the link to my replit :
boilerplate-budget-app-10 - Replit[https://replit.com/@EnekoCUBILLAS1/boilerplate-budget-app-10#budget.py]
So this question is going to sound pretty damn stupid but it’s been a few months since I’ve coded so I am a little rough on the edges. I have to get into a good rythm
I have been doing the Budget App challenge and I am at the stage of creating the chart. I have a huge doubt and I think that once I have that doubt resolved I can continue on.
How can we access a class from an outer function is basically my main question?
Let me explain
Here is my code so far:
class Category:
def __init__(self, category, ledger = None, balance = 0):
if ledger is None:
ledger = []
self.category = category
self.ledger = ledger
self.balance = balance
def __str__(self):
output = self.category.center(30,"*") + "\n"
total = 0
for dictionnary in self.ledger:
desc_length = 30 - len(dictionnary["description"][:23])
floated = dictionnary["amount"]
total += dictionnary["amount"]
output += dictionnary["description"][:23] + "{:.2f}".format(floated).rjust(desc_length) + "\n"
output += "Total: " + str(total)
return output
def deposit(self, amount, description = ""):
self.balance += amount
self.ledger.append({"amount": amount, "description": description})
def withdraw(self, amount, description = ""):
if amount > self.balance:
return False
else:
self.ledger.append({"amount": + amount*-1, "description": description})
self.balance -= amount
return True
def get_balance(self):
return self.balance
def transfer(self, amount, category):
if amount > self.balance:
return False
else:
self.ledger.append({"amount": + amount*-1, "description": "Transfer to " + category.category})
self.balance -= amount
category.ledger.append({"amount": amount, "description": "Transfer from " + self.category})
category.balance += amount
return True
def check_funds(self, amount):
if amount > self.balance:
return False
else:
return True
def create_spend_chart(categories):
for category in categories:
for name in category.
What I want to do is go over the list provided in categories and from the names in that list, reach for the info in the class.
As an example, “food” is present in the list. I want to access that class and more precisely all the withdrawals, add them etc…
Thanks for the help and I know the stupidity of this question