Build a Budget App Project - Build a Budget App Project

Tell us what’s happening:

I don’t know how to tell what it is saying is wrong in the console(F12). It is on the last portion, and everything looks the same except at the end it shows - t then on the next line ? ^ and then the same thing but on the same line.

Your code so far

class Category:

    def __init__(self, category):
        self.category = category
        self.ledger = []
        self.budget = 0.0

    def __str__(self):
        print_out = ''
         
        cat_len = len(self.category)//2
        cat_start = 15 - cat_len
        
        star_end = 15 - (len(self.category) - cat_len) 
        line_title = ''
        for _ in range(cat_start):
            line_title = line_title + '*'

        line_title = line_title + self.category

        for _ in range(star_end):
            line_title = line_title + '*' 

        print_out += line_title + '\n' 
        for item in self.ledger:
            str_amount = "{:.2f}".format( item['amount'] )
            print_out += item['description'][:23].ljust(0) + str_amount.rjust(30-len(item['description'][:23])) +'\n'

        print_out += 'Total: ' + str(self.budget)

        
        return print_out

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


    def withdraw(self, amount, description=''):
        amount = 0-amount 
        if not self.check_funds(abs(amount)):
            return False
        self.budget += amount
        self.ledger.append({'amount':  amount, 'description': description})
        return True

    def get_balance(self):
        
        return self.budget

    def transfer(self, amount, transfer_category):
        
        new_category = transfer_category.category
        if not transfer_category:
            transfer_category = Category(transfer_category)
        
        if not self.check_funds(amount):
            return False

        
        self.withdraw(amount, 'Transfer to ' + new_category)

        transfer_category.deposit(amount, 'Transfer from ' + self.category)

        return True


    def check_funds(self, amount):
        if self.budget - amount < 0:
            return False
        return True

def create_spend_chart(categories):
    max_length = 0
    total = 0.0
    item_list = {}
    percent_list = {}
    print_list = []
    print_string = ''
    cat_count = 0
    for cat in categories:
        cat_count += 1
        max_length = max(max_length, len(cat.category))
        line_total = 0.0
        for line_item in cat.ledger:
            if float(line_item['amount']) < 0:
                line_total += abs(float(line_item['amount']))
                total += abs(float(line_item['amount']))
        item_list[cat.category] = line_total
    
    for cat in categories:
    
        percent = int(item_list[cat.category]/total*100) - (int(item_list[cat.category]/total*100) % 10)
        percent_list[cat.category] = percent
         
    
    print_list.append('Percentage spent by category\n')
    for i in range(10,-1,-1):
        marker = i * 10
        
        marker_string = str(marker).rjust(3) + '|'
        print_list.append(marker_string)
        for cat in categories:
            
            if percent_list[cat.category] >= marker:
                print_list.append(' o ')
            else: print_list.append('   ')
        print_list.append(' \n')
    
    for i in print_list:
        print_string += i
    print_string += '    ' + (('---' * cat_count) + '-\n')

    for i in range(max_length):
        print_string += '    '
        for cat in categories:
            if len(cat.category) >i:
                print_string += ' ' + cat.category[i] + ' '
            else: 
                print_string += '   '
        print_string += '\n'

    return print_string


Your browser information:

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

Challenge Information:

Build a Budget App Project - Build a Budget App Project

An assertion error 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

- 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 .

I hope this helps interpret your error!

You can see your assertion error here:

AssertionError: 'Perc[226 chars]F  E \n     u  o  n \n     s  o  t \n     i  d[137 chars]t \n' != 'Perc[226 chars]F  E  \n     u  o  n  \n     s  o  t  \n     i[148 chars] t  '

It helps to break it up into two lines like this to compare

AssertionError: 
'Perc[226 chars]F  E \n     u  o  n \n     s  o  t \n     i  d[137 chars]t \n' != 
'Perc[226 chars]F  E  \n     u  o  n  \n     s  o  t  \n     i[148 chars] t  '

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

That helped a ton, thanks

1 Like