Tell us what’s happening:
My code isn’t passing step 16 of this challenge:“Printing a Category instance should give a different string representation of the object.”
The output is identical (as far as I can tell) to the example.
Is there a real error in my code somewhere or is the fcc test just being picky?
Or is this one of those situations where the test won’t pass until I get further into the next part of the project?
Thanks!
Your code so far
class Category:
def __init__(self, name):
self.name = name
self.ledger =[]
def deposit(self, amount, description=''):
self.ledger.append({'amount': amount, 'description': description})
def withdraw(self, amount, description=''):
if self.check_funds(amount) == True:
self.ledger.append({'amount': -amount, 'description': description})
return(True)
else:
return(False)
def get_balance(self):
balance = 0
for transaction in self.ledger:
balance += transaction['amount']
return(balance)
def transfer(self, amount, other_cat):
if self.check_funds(amount) == True:
self.ledger.append({'amount': -amount, 'description': f"Transfer to {other_cat.name}"})
other_cat.ledger.append({'amount': amount, 'description': f"Transfer from {self.name}"})
return(True)
else:
return(False)
def check_funds(self, amount):
if amount <= self.get_balance():
return(True)
else:
return(False)
def __str__(self):
title = self.name
output_lines = ""
for entry in self.ledger:
desc = entry['description'][:23]
money = str(entry['amount'])[:7]
fill_len = 30 - (len(desc) + len(str(money)))
fill_str = " " * fill_len
line = f"\n{desc}{fill_str}{money}"
output_lines += line
return (f"{title.center(30, '*')} {output_lines}\nTotal: {self.get_balance()}")
food = Category("Food")
clothing = Category("Clothing")
auto = Category("Auto")
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
food.transfer(50, clothing)
print(food)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App - Build a Budget App
