Tell us what’s happening:
That create spend chart is really tripping me up
I just don’t understand how to do this. Its super hard for me without visualisation Can anybody help me please?
Thanks a lot
Good Day
Mikhael
Your code so far
class Category:
def __init__(self, name):
self.name = name
self.ledger = []
def get_balance(self):
balance = 0
for transac in self.ledger:
balance += transac['amount']
return balance
def check_funds(self, amount):
funds = self.get_balance()
if (amount > funds):
return False
else:
return True
def deposit(self, amount, description=""):
self.ledger.append({'amount': amount, 'description': description});
def withdraw(self, amount, description=""):
if (self.check_funds(amount)):
self.ledger.append({'amount': -amount, 'description': description});
return True
else:
return False
def transfer(self, amount, instance):
withdraw_desc = f"Transfer to {instance.name}"
deposit_desc = f"Transfer from {self.name}"
if self.withdraw(amount, withdraw_desc):
instance.deposit(amount, deposit_desc)
return True
else:
return False
def __str__(self):
title = self.name.center(30, "*")
for entry in self.ledger:
float_amount = f"{entry['amount']:.2f}"
title += f"\n{entry['description'][:23].ljust(23)}"
title += f"{float_amount[:7].rjust(7)}"
title += f"\nTotal: {self.get_balance()}"
return title
def create_spend_chart(categories):
output = "Percentage spent by category\n"
def sum_withdraw(category):
total_withdraw = 0
for entry in category.ledger:
if entry["amount"] < 0:
total_withdraw += entry["amount"]
return total_withdraw
def percentage(category):
return output
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15
Challenge Information:
Build a Budget App - Build a Budget App