Tell us what’s happening:
Hi there,
I can’t get the final test on the Budget App to pass.
Everything seems to work fine. What am I missing?
Your code so far
```py
class Category:
def __init__(self, category):
self.category = category
self.ledger = []
self.balance = 0
def __str__(self):
title = self.category.center(30, "*")
ledger = ""
for item in self.ledger:
listing = "{:<23}".format(item["description"])
money = "{:>7.2f}".format(item["amount"])
ledger += "\n{}{}".format(listing[:23], money[:7])
total = "\nTotal: {:.2f}".format(self.balance)
return title + ledger + total
def deposit(self, amount, description = ""):
self.ledger.append({"amount": amount, "description": description})
self.balance += amount
def withdraw(self, amount, description = ""):
if amount > self.balance:
return False
else:
self.ledger.append({"amount": -1 * amount, "description": description})
self.balance -= amount
return True
def get_balance(self):
return self.balance
def transfer(self, amount, other_category):
if self.withdraw(amount, "Transfer to {}".format(other_category.category)):
other_category.deposit(amount, "Transfer from {}".format(self.category))
return True
else:
return False
def check_funds(self, amount):
if amount > self.balance:
return False
else:
return True
def create_spend_chart(categories):
spent_values = []
for category in categories:
category_total = 0
for transaction in category.ledger:
if transaction["amount"] < 0:
category_total += abs(transaction["amount"])
spent_values.append(category_total)
total_spent = sum(spent_values)
percentages = list(map(lambda value: (((value / total_spent) * 10) // 1) * 10, spent_values))
title = "Percentage spent by category\n"
chart = ""
for value in reversed(range(0, 101, 10)):
chart += str(value).rjust(3) + "|"
for percent in percentages:
if value <= percent:
chart += " o "
else:
chart += " "
chart += "\n"
labels = (" " * 4) + ("---" * len(categories)) + "-\n"
descriptions = list(map(lambda x: x.category, categories))
max_length = max(map(lambda x: len(x), descriptions))
descriptions = list(map(lambda x: x.ljust(max_length), descriptions))
for letter in zip(*descriptions):
labels += (" " * 4) + "".join(map(lambda x: x.center(3), letter)) + " \n"
return (title + chart + labels)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Challenge Information:
Scientific Computing with Python Projects - Budget App
https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/budget-app