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