Build a Budget App - Build a Budget App

Tell us what’s happening:

I cannot pass 19, 20, 23, or 24 which all deal with the format of the chart. I do not know how to check it using F12. What do I look for in F12?
Thank You for the help.

Your code so far


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Budget App - Build a Budget App

in the browser console you would see extra output from the tests

Click here to see more infos on how to read the extra output from the tests

The assertion error and diff gives you a lot of information to track down a problem. For example:

AssertionError: 'Year' != 'Years'
- Year
+ Years
?     +

Your output comes first, and the output that the test expects is second.

AssertionError: ‘Year’ != ‘Years’

Your output: Year does not equal what’s expected: Years

This is called a diff, and it shows you the differences between two files or blocks of code:

- Year
+ Years
?     +

- Dash indicates the incorrect output
+ Plus shows what it should be
? The Question mark line indicates the place of the character that’s different between the two lines. Here a + is placed under the missing s .

Here’s another example:

E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert '  3801      123    \n   - 2     + 49    \n------    -----    \n' == '  3801      123\n-    2    +  49\n------    -----'
E         -   3801      123
E         +   3801      123    
E         ?                ++++
E         - -    2    +  49
E         +    - 2     + 49    
E         - ------    -----
E         + ------    -----    
E         ?                +++++

The first line is long, and it helps to view it as 2 lines in fixed width characters, so you can compare it character by character:

'  3801      123    \n   - 2     + 49    \n------    -----    \n'
'  3801      123\n-    2    +  49\n------    -----'

Again, your output is first and the expected output is second. Here it’s easy to see extra spaces or \n characters.

E         -   3801      123
E         +   3801      123    
E         ?                ++++

Here the ? line indicates 4 extra spaces at the end of a line using four + symbols. Spaces are a little difficult to see this way, so it’s useful to use both formats together.

I hope this helps interpret your error!

If you want more help, you will need to provide your code.

Please update the message to include your code. The code was too long to be automatically inserted by the help button.

When you enter a code, 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 (').

Here is my code if it helps

import math
class Category:
    def __init__(self, category):
        self.category = category
        self.ledger = []
        self.budget = 0
    def deposit(self, amount, description = ''):
        self.budget += amount
        self.ledger.append({'amount': amount, 'description': description})
    def withdraw(self, amount, description = ''):
        if self.check_funds(amount):
            self.ledger.append({'amount': -amount, 'description': description})
            self.budget -= amount
            return True
        else:
            return False
    def get_balance(self):
        return self.budget
    def transfer(self, amount, other_category):
        if self.check_funds(amount):
            self.budget -= amount
            self.ledger.append({'amount': -amount, 'description': f'Transfer to {other_category.category}'})
            other_category.deposit(amount, f'Transfer from {self.category}')
            return True
        else:
            return False
    def check_funds(self, amount):
        if self.get_balance() >= amount:
            return True
        else:
            return False
    def __str__(self):
        category_print = ''
        category_print += self.category.center(30, '*')
        category_print += '\n'
        for item in self.ledger:
            description = item['description']
            amount = str(item['amount'])
            if '.' not in amount:
                amount = (f'{amount}.00')
            category_print += f'{description[0:23]:<23}'
            category_print += f'{amount[-7:]:>7}'
            category_print += '\n'
        category_print += f'Total: '
        category_print += f'{self.get_balance():}'
        return category_print

food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
clothing.withdraw(20,'clothes')
auto = Category('Auto')
auto.deposit(100, 'initial deposit')
auto.withdraw(10.25, 'oil change')
print(food)
print(clothing)
print(auto)
def create_spend_chart(categories):
    amount_of_categories = len(categories)
    total_amount = []
    total_numbers = 0
    percentages = []
    total_percentage = 100
    category_type = []
    bar_chart = ''
    for category in categories:
        category_type.append(category.category)
    for item in categories:
        item = item.category
    for category in categories:
        negative_amount = 0
        for category.description in category.ledger:
            amount = category.description['amount']
            if amount < 0:
                negative_amount += amount
        total_amount.append(negative_amount)
    for items in total_amount:
        total_numbers += abs(math.floor(items))
    for item in total_amount:
        try:
            percentages.append(abs(round(item/total_numbers, 1))*10)
        except ZeroDivisionError:
            result = 0
    category_percentage_pairs = dict(zip(category_type,percentages))
    for num in reversed(range(11)):
        if num == 0:
            bar_chart += '  0|'
            for value in category_percentage_pairs.values():
                if value >= 0:
                    bar_chart += ' o ' 
                else:
                    print('   ')
        elif num == 10:    
            bar_chart += '100|'
            for value in category_percentage_pairs.values():
                if value == 100:
                    bar_chart += ' o ' 
                else:
                    print('   ')
        else:
            bar_chart += f' {num}0|'
            for value in category_percentage_pairs.values():
                if value >= num:
                    bar_chart += ' o ' 
                else:
                    print('   ')
        bar_chart += '\n'
    category_names = category_percentage_pairs.keys()
    max_len = 0
    for word in category_names:
        if len(word) > max_len:
            max_len = len(word)
    total_row = ''
    row = '    '
    for i in range(max_len):
        if i != 0:
            row = '\n    '
        for words in category_names:
            if i < len(words):
                row += f' {words[i]} '
            else:
                row += '   '
        total_row += row + '  '
    return 'Percentage spent by category' + '\n' + bar_chart + '    ' + (amount_of_categories)*'---' + '-' + '\n' + total_row
print(create_spend_chart([food, clothing, auto]))

Did you check the errors in your browser’s console and read the instructions ILM provided on how to interpret them?

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