Python Budget App - my graph looks be good, but get an error with spacing

I try to finish my Budget App but I realy cann’t see this error. Can anybody help me?

 python main.py
973.96
Food
initial deposit 1000.00
groceries -10.15
restaurant and more foo -15.89
Transfer to Clothing -50.00
Total: 923.96
Clothing
Transfer from Food 50.00
-25.55
Total: 24.45
Percentage spent by category
100|
90|
80|
70|
60|
50|
40|
30| o o
20| o o o
10| o o o
0| o o o
----------
F C A
o l u
o o t
d t o
h
i
n
g

.F…

FAIL: test_create_spend_chart (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-budget-app-6/test_module.py”, line 94, in test_create_spend_chart
self.assertEqual(actual, expected, ‘Expected different chart representation. Check that all spacing is exact.’)
AssertionError: ‘Perc[364 chars] m \n e \n n \n t \n’ != 'Perc[364 chars] m \n e \n n \n t ’
Percentage spent by category
100|
90|
80|
70| o
60| o
50| o
40| o
30| o
20| o o
10| o o
0| o o o
----------
B F E
u o n
s o t
i d e
n r
e t
s a
s i
n
m
e
n

  •        t  
    

? -

  •        t   : Expected different chart representation. Check that all spacing is exact.
    

Ran 11 tests in 0.003s

FAILED (failures=1)

This is my code.
class Category:
def init(self, category):
self.ledger = list()
self.category = category
def str(self):
output = self.category.center(30, “*”)
output += “\n”
total = 0
txt = “{:<23}{:>7.2f}”
for item in self.ledger:
total+=item[“amount”]
output += txt.format(item[“description”][:23],item[“amount”])
output += “\n”
output += “Total:”
txt = “{:>7}”
output += txt.format(total)
return output
def deposit(self, amount, description=""):
newitem = {
“amount”: amount,
“description”: description
}
self.ledger.append(newitem)
def get_balance(self):
balance = 0
for item in self.ledger:
balance += item[“amount”]
return balance
def withdraw(self, amount, description=""):
if self.check_funds(amount):
newitem = {
“amount”: -amount,
“description”: description
}
self.ledger.append(newitem)
return True
else:
return False
def transfer(self, amount, destination_budget_category):
if self.check_funds(amount):
newitem = {
“amount”: -amount,
“description”: "Transfer to "+ destination_budget_category.category
}
self.ledger.append(newitem)
newitem = {
“amount”: amount,
“description”: "Transfer from "+ self.category
}
destination_budget_category.ledger.append(newitem)
return True
else:
return False
def check_funds(self, amount):
if amount > self.get_balance():
return False
else:
return True

def create_spend_chart(categories):
##print(“Percentage spent by category”)
output = “Percentage spent by category\n”
sumlist =
alltotal = 0
for categ in categories:
cattotal = 0
for item in categ.ledger:
if item[“amount”] < 0 and not item[“description”].startswith(‘Transfer’):
alltotal += -item[“amount”]
cattotal += -item[“amount”]
sumlist.append(cattotal)
perclist =
for sum in sumlist:
perc = 10int(10sum/alltotal)
perclist.append(perc)
for i in [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0 ]:
txt = “{:>3}”
row = txt.format(i)
#row += “|”
row += “| "
for catperc in perclist:
if catperc >= i:
#row += " o "
row += “o "
else:
row += " "
#if row.rfind(‘o’) == -1:
# row = row[:5]
#else:
# row = row[:row.rfind(‘o’)+2]
##print(row)
output = output + row +”\n”
row = " -"
for i in range(len(categories)):
row += “—”
##print(row)
output = output + row +"\n"
maxlen = 0
for i in range(len(categories)):
if len(categories[i].category) > maxlen:
maxlen = len(categories[i].category)
for i in range(maxlen):
row = " "
for j in range(len(categories)):
if i >= len(categories[j].category):
row += " "
else:
row = row + categories[j].category[i] + " "
##print(row)
output = output + row +"\n"
return output

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.