Build a Budget App Project - Build a Budget App Project

Tell us what’s happening:

Even though it is returning the same thing, the interpreter still returns an error. NOTE: I also tried with \ simple.

Your code so far

class Category:
    def __init__(self, kind):
        self.kind = kind.lower()
        self.ledger = []
        self.balance = 0

    def __str__(self):
        header = f'{self.kind.capitalize():*^30}\n'
        items = ""
        for i in self.ledger:
            descrition = i['description'][:23]
            amount = f"{i['amount']:.2f}"
            items += f"{descrition:<23}{amount:>7}\n"
        total = f'Total: {self.balance:.2f}'
        return header + items + total

    def deposit(self, amount, description=''):
        self.ledger.append({'amount': amount, 'description': description})
        self.balance += amount
        return True

    def withdraw(self, amount, description=''):
        if self.check_funds(amount):
            self.ledger.append({'amount': -amount, 'description': description})
            self.balance -= amount
            return True
        else:
            return False

    def get_balance(self):
        return self.balance

    def transfer(self, amount, destination):
        if self.check_funds(amount):
            if self.withdraw(amount, f'Transfer to {destination.kind.capitalize()}'):
                destination.deposit(amount, f'Transfer from {self.kind.capitalize()}')
                return True
        else:
            return False

    def check_funds(self, amount):
        if self.balance >= amount:
            return True
        else:
            return False


def create_spend_chart(kinds):
    spent = [sum(-item["amount"] for item in k.ledger if item["amount"] < 0) for k in kinds]
    total_spent = sum(spent)

    percentages = [int((amount / total_spent) * 100 // 10) * 10 for amount in spent]
    print(percentages)

    chart = "Percentage spent by category\\n"

    for i in range(100, -10, -10):
        chart += f"{i:>3}|"
        for percentage in percentages:
            chart += " o " if percentage >= i else "   "
        chart += " \\n"

    chart += "    " + "-" * (3 * len(kinds) + 1) + "\\n"

    max_length = max(len(k.kind) for k in kinds)
    for i in range(max_length):
        chart += "    "
        for k in kinds:
            name = k.kind.capitalize()
            chart += f" {name[i] if i < len(name) else ' '} "
        if i != max_length - 1:
            chart += " \\n"

    return chart




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0

Challenge Information:

Build a Budget App Project - Build a Budget App Project

\\n escapes the new line character making it all in single line separated with \n.

If you take a look at the browser’s console, there are details regarding the failing test. Other than the escaped new line characters, it appears there’s inconsistent space at the end of string - comparing to the other lines.