Tell us what’s happening:
I am not understanding why test 20 and 24 are failing . I am getting desired output when this code is executed in VSCode.
Error in browser console -
n {
message: “Unspecified AssertionError”,
showDiff: false,
actual: null,
expected: undefined,
stack: "AssertionError: Unspecified AssertionError
at test (eval at #s (https://www.freecodecamp.org/js/test-runner/7.2.0/python-test-evaluator.js:2:155314), :39:5)
at #s (https://www.freecodecamp.org/js/test-runner/7.2.0/pyt
Your code so far
class Category:
def __init__(self, name):
self.name = name
self.ledger = []
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
return False
def get_balance(self):
return sum(item["amount"] for item in self.ledger)
def transfer(self, amount, category):
if self.check_funds(amount):
self.withdraw(amount, f"Transfer to {category.name}")
category.deposit(amount, f"Transfer from {self.name}")
return True
return False
def check_funds(self, amount):
return self.get_balance() >= amount
def __str__(self):
title = f"{self.name:*^30}\n"
body = ""
for item in self.ledger:
body += f"{item['description'][:23]:<23}{item['amount']:>7.2f}\n"
return title + body + f"Total: {self.get_balance()}"
def create_spend_chart(categories):
result = "Percentage spent by category\n"
spent = []
for category in categories:
total = 0
for item in category.ledger:
if item["amount"] < 0:
total += -item["amount"]
spent.append(total)
total_spent = sum(spent)
percentages = [int((s / total_spent) * 100) // 10 * 10 for s in spent]
for level in range(100, -1, -10):
result += f"{level:>3}|"
for p in percentages:
result += " o " if p >= level else " "
result += "\n"
result += " " + "-" * (3 * len(categories) + 1) + "\n"
max_len = max(len(cat.name) for cat in categories)
for i in range(max_len):
result += " "
for cat in categories:
result += (cat.name[i] if i < len(cat.name) else " ") + " "
result += "\n"
return result[:-1]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App - Build a Budget App