Scientific Computing: Budget App - create_spend_chart

Hi everyone,

I’ve been stuck at the ‘spend chart’ part of this project for over two weeks now, with no end in sight. The output looks identical but i’m getting one failure which i know ,most likely, is due to newlines and spaces but i can’t figure it out even when i set self.maxDiff=None, as suggested.

The error is:

Diff is 819 characters long. Set self.maxDiff to None to see it. : Expected different chart representation. Check that all spacing is exact.

I’ve seen 2-3 similar posts here but for some reason there was no response, i hope this one will fare better .

Thanks in advance to anyone that will take the time to help
(link to project:

Your code so far

class Category:
    name = ""
    withdrawals = 0

    def __init__(self, name): = name
        self.ledger = list()

    def __str__(self):
        represent =, "*") + "\n"

        for item in self.ledger:
            row = f"{item['description'][:23]:23}{item['amount']:7.2f}"
            represent += f'{row}\n'

        represent += "Total: " + str(self.get_balance())
        return represent

    def deposit(self, amount, description=""):
        d = {"amount": float(amount), "description": description}

    def check_funds(self, amount):
        total = 0
        for item in self.ledger:
            total += item['amount']
        if float(amount) <= total:
            return True
            return False

    def withdraw(self, amount, description=""):
        if self.check_funds(amount) is True:
            d = {"amount": float(-amount), "description": description}
            self.withdrawals += amount
            return True
            return False

    def get_balance(self):
        total = 0
        for item in self.ledger:
            total += item['amount']
        return total

    def transfer(self, amount, category2):
        if self.check_funds(amount) is True:
            description1 = f'Transfer from {}'
            description2 = f'Transfer to {}'
            d1 = {"amount": float(-amount), "description": description2}
            self.withdrawals += amount
            d2 = {"amount": float(amount), "description": description1}
            return True
            return False

def create_spend_chart(categories):
    category = Category
    expenditure = dict()
    pct_exp = dict()
    total_exp = 0
    for category in categories:
        expenditure[] = category.withdrawals
        total_exp += category.withdrawals
    for key, value in expenditure.items():
        pct_exp[key] = value/total_exp*100

    row = "Percentage spent by category"
    for i in range(100, -1, -10):
        row += f'\n{str(i).rjust(3)}|'
        for j in pct_exp.values():
            if j > i:
                row += " o "
                row += "   "
    row += "\n    ----------\n"

    max_length = max(expenditure.keys(), key=len)

    for i in range(len(max_length)):
        row += " " * 4
        for name in expenditure.keys():
            if i < len(name):
                row += " " + name[i] + " "
                row += " " * 3
        row += " \n"

    row = row.rstrip() + " " * 2

    return row

Your browser information:

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

Challenge: Budget App

Link to the challenge:

hi, you can go to the tests file and check the supposed result of the test that fails. In this case, its a string, which your code is expected to reproduce. If you look closely you can notice how each new line is structured. For example at the end of every line, there is an extra white space ' ' . The separator line which you use (-------) is also supposed to be of adjustable length(“two spaces past the final bar”).

Here is link to my solution, which is processing the tests OK. Maybe looking at it you can figure out where your code differs in output

1 Like

First of all, thanks for taking the time to help.
I hadn’t realised the separator line was supposed to be adjustable, i’ll try amending my code with that and get back to you

Hi Sylvant - thanks for the tips. I just came on here short of pulling my hair out. It looked okay on the screen, but realised that the grader was very pedantic about spacing and \n characters. Combing through each error line as you suggested paid off. Thanks a mil!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.