What am I doing wrong here? It prints exactly as should each time. I see no difference between expected and actual…

FreeCodeCamp-BudgetApp:

TestModule:

**Error 1: Line 102**

self.assertEqual(actual, expected, ‘Expected different chart representation. Check that all spacing is exact.’)

Expected Result:

"Percentage spent by category\n100| \n 90| \n 80| \n 70| o \n 60| o \n 50| o \n 40| o \n 30| o \n 20| o o \n 10| o o \n 0| o o o \n ----------\n B F E \n u o n \n s o t \n i d e \n n r \n e t \n s a \n s i \n n \n m \n e \n n \n t "

**Error 2: Line 91**

self.assertEqual(actual, expected, ‘Expected different string representation of object.’)

Expected Result:

f"*Food*\ndeposit 900.00\nmilk, cereal, eggs, bac -45.67\nTransfer to Entertainme -20.00\nTotal: 834.33"

Here’s my code:

```
# Budget App
class Category:
def __init__(self, name):
self.name = name
self.balance = 0
self.ledger = []
def __repr__(self): # or __str__ ?
s = f"{self.name:*^30}\n"
# Here’s the grammar of a format specifier: [[fill]align][sign][#][0][width][grouping_option][.precision][type]
for n in self.ledger:
descriptions = (n['description'])[0:23] # each character of the string up until the 23rd.
amounts = str(n['amount']) # entire amount as a string.
d = (f"{descriptions: <23}")
a = (f"{float(amounts): >#7.2f}\n")
s += d
s += (a)[0:7] + "\n"
s += (f"Total: {self.balance:<#23.2f}\n")[0:30]
#s += "\n"
return s
# DEFINE METHODS = FUNCTIONS (with self-contained variables)
def get_balance(self):
return self.balance
def check_funds(self, amount): # per category
self.amount = amount
if self.amount <= self.balance:
return True
else:
return False
def deposit(self, amount, description=""):
self.balance += amount
self.ledger.append({"amount": amount, "description": description}) # can take ONE argument
return True
def withdraw(self, amount, description=""):
if self.check_funds(amount):
self.balance -= amount
self.ledger.append({"amount": -abs(amount), "description": description})
return True
else:
amount = 0
return False
def transfer(self, amount, instance):
if self.check_funds(amount):
description_transfer = f"Transfer ${amount} from {self.name} to {instance.name}."
self.withdraw(amount, f"Transfer to {instance.name}")
instance.deposit(amount, f"Transfer from {self.name}")
return True
else:
return False
def print_ledger(self):
print(self.__str__())
def get_withdrawls(self):
global cat_total
cat_total = 0
for item in self.ledger[0:]:
if int(item['amount']) < 0:
cat_total += item['amount']
return cat_total
# -------------------OUTSIDE OF CLASS------------------- #
def get_totals(names):
total = 0
totals = []
for each in names:
total += Category.get_withdrawls(self=each)
totals.append(Category.get_withdrawls(self=each))
rounded = list(map(lambda x: math_reduce(x / total), totals)) # x is each in totals list, x/grand total for each.
return rounded
def math_reduce(n):
multiplier = 10
return int(n * multiplier) / multiplier
# ***********************************^^^WORKS^^^*********************************** #
def create_spend_chart(categories):
p = "Percentage spent by category\n"
percentages = []
names_list = []
nums_list = []
padded = []
for cat in categories: # use.method
names_list.append(cat.name)
nums_list.append(cat.get_withdrawls())
height = (len(max(names_list, key=len)))
padded = [name.ljust(height) for name in names_list]
percentages.append(get_totals(categories))
# PERCENTAGES FOR CHART
percentages_big = []
for i in percentages[0]:
multiplied = i * 100
percentages_big.append(multiplied)
# THE CHART
for n in range(100, -1, -10):
p += f"{n:>3}" + "| "
for percent in percentages_big:
if percent >= n:
p += "o "
else:
p += " "
p += "\n"
p += f"{' ' + '-' + (('-' * 3) * len(categories))}\n"
for name in zip(*padded):
p += (' ' + (' '.join(name))) + ' \n'
return p
# ***********************************END OF PROJECT*********************************** #
Thanks,
-T
```