Build a Budget App Project - Build a Budget App Project

Tell us what’s happening:

I’m running into issues with Test 16: “Printing a Category instance should give a different string representation of the object.”

Upon opening the inspection console, I’m receiving the following error:

Object { message: “Unspecified AssertionError”, showDiff: false, actual: null, expected: undefined }
Uncaught TypeError: can’t access property “dimensions” of undefined

I’m confused about what is going on and what I need to change to pass this test and keep moving. I’ve compared my output to the example and can’t find any differences and the error doesn’t seem to be implying that that is what is wrong.

Your code so far

class Category:
    def __init__(self,category=''):
        self.category = category
        self.ledger = []
        self.balance = 0
    
    def __repr__(self):
    # Category title
        strings = f"{self.category:*^30}\n"
    # Ledger items
        activity = lambda description,amount: f'{description:<23}{amount:>7}\n'
        for items in self.ledger:
            description = items['description'][0:23] if len(items['description']) > 23 else "initial deposit" if items['description'] == 'deposit' else items['description']
            amount = f"{items['amount']:.2f}"
            strings += activity(description,amount)
    # Total
        strings += f"Total: {self.get_balance():.2f}"
        return strings
    
    def get_balance(self):
        self.balance = 0
        for items in self.ledger:
            self.balance += items['amount']
        return self.balance
    
    def _deposit(self, ledger, amount, description):
        ledger.append({'amount': amount, 'description': description})
        return ledger
    
    def deposit(self, amount, description=""):
        self._deposit(self.ledger,amount,description)
        return self.ledger
    
    def check_funds(self,amount):
        if amount < 0:
            amount = -amount
        if amount <= self.get_balance():
            return True
        else: return False
    
    def withdraw(self, amount, description=""):
        if amount > 0:
            amount = -amount
        if self.check_funds(amount):
            self._deposit(self.ledger,amount,description)
            return True
        else: return False
    
    def transfer(self,amount,transfer_category):
        if self.check_funds(amount):
            transfer_category.deposit(amount,'Transfer from ' + str(self.category))
            self.withdraw(amount,'Transfer to ' + str(transfer_category.category))
            return True
        else: return False

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:143.0) Gecko/20100101 Firefox/143.0

Challenge Information:

Build a Budget App Project - Build a Budget App Project

Hi @a-feltesdeyapp

When I enter deposit as a description when adding funds to a category, initial deposit is printed.

I don’t think the tests are expecting that behaviour.

Happy coding

That fixed it, thank you :blush: . However, I think that a minor edit should probably be made to the example code for that section because the example they gave implied the formatting I had originally implemented.

Here is an example usage

food = Category('Food')
food.deposit(1000, 'deposit')    # just the description 'deposit'
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
print(food)

And here is an example of the output:

*************Food*************
initial deposit        1000.00    # but here it has become 'initial deposit'
groceries               -10.15
restaurant and more foo -15.89
Transfer to Clothing    -50.00
Total: 923.96

The inconsistency just ended up being unnecessarily confusing.

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.