Budget app spend chart

please help me out have been stock for weeks , I got one fail

https://replit.com/@RahmonOlobi/boilerplate-budget-app-2#budget.py

class Category:
    withdraws = 0
    name = ''

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

    def __repr__(self):
        display_menu = self.name.center(30, '*') + '\n'
        for element in self.ledger:
            row = f"{element['description'][:23]:23}{element['amount']:7.2f}"
            display_menu += row + '\n'
        display_menu += "Total: " + str(self.get_balance())
        return display_menu

    def deposit(self, amount, description=''):
        deposit_list = {'amount': amount, 'description': description}
        self.ledger.append(deposit_list)

    def check_funds(self, amount):
        total_funds = 0
        for transactions in self.ledger:
            total_funds += transactions['amount']
        if float(total_funds) >= amount:
            return True
        else:
            return False

    def withdraw(self, amount, description=''):
        if self.check_funds(amount) is True:
            withdraw_list = {'amount': float(-amount), 'description': description}
            self.ledger.append(withdraw_list)
            self.withdraws += amount
            return True
        else:
            return False

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

    def transfer(self, amount, category_2):
        if self.check_funds(amount) is True:
            description_1 = f'Transfer to {category_2.name}'
            description_2 = f'Transfer from {self.name}'
            self.ledger.append({'amount': -1 * amount, 'description': description_1})
            self.withdraws += amount
            category_2.ledger.append({'amount': amount, 'description': description_2})
            return True
        else:
            return False


def create_spend_chart(categories):
    chart = 'Percentage spent by category'
    category = Category
    expenses = dict()
    total = 0
    percentage = []
    count = 0
    max_len = 0
    for category in categories:
        expenses[category.name] = category.withdraws
        total += category.withdraws
        count += 1

    for k, v in expenses.items():
        percentage.append(v / total * 100)
        if len(k) > max_len:
            max_len = len(k)

    for i in range(100, -1, -10):
        chart += f'\n{str(i).rjust(3)}|'
        for percent in percentage:
            if percent > i:
                chart += ' o '
            else:
                chart += '   '
    chart += '\n' + '    ' + ('-' * (count * 3 + 1)) + '\n'
    for i in range(max_len):
        chart += ' ' * 4
        for k in expenses.keys():
            if i < len(k):
                chart += ' ' + k[i] + ' '
            else:
                chart += ' ' * 3
        chart += '\n'
    return chart

Please include a link to your replit so we can see the error.

1 Like

(boilerplate-budget-app-2 - Replit)

AssertionError: 
'Perc[34 chars]     \n 90|         \n 80|         \n 70|    o[318 chars]t \n' != 
'Perc[34 chars]      \n 90|          \n 80|          \n 70|  [340 chars] t  '

Here is the error and the first line is your output. It’s one space to short.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

please tell me what to or where to edit in my line of code because I have looked at and don’t know exactly what to add or remove

Why the 3 here? This line is probably where you have an issue.

then what do I put there

What are you trying to do with that line?

I have two of it there one line 81 and the other at line 92 .
line 81 is under conditional statement , if the percentage spent(category) is less than chart percentage (100 - 0) it will create a three empty space for next Category to be in other . So as line 92 for printing Category name.

But why three spaces?

three space breakdown
a space after the bar(|)
a space for percent bar(0)
a space after the percent bar

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