Hi. I need to pick your brilliant brain(s) . Now I have no clue where I have to change to get the spacing correctly. I don’t know what maxDiff means. either.
I appreciate your help. Thank you!
class Category:
def __init__(self, name):
self.name = name
self.ledger = []
def get_balance(self):
prices = []
for i in self.ledger:
prices.append(i["amount"])
bal = sum(prices)
return bal
def check_funds(self, amount):
if amount <= self.get_balance():
return True
else:
return False
def deposit(self, amount, description =""):
dep_dict = {"amount": amount, "description": description}
self.ledger.append(dep_dict)
def withdraw(self, amount, description =""):
if self.check_funds(amount) == True:
withd_dict = {"amount": amount, "description": description}
self.ledger.append(withd_dict)
return True
else:
return False
def transfer(self, amount, destination):
if self.check_funds(amount) == True:
self.withdraw(amount, description = "Transfer to " + destination.name)
destination.deposit(amount, description = "Transfer from " + self.name)
return True
else:
return False
def __str__(self):
table = self.name.center(30, "*") + "\n"
for i in self.ledger:
table += f"{i['description'][0:23].ljust(23)}{format(i['amount'], '.2f').rjust(7)}\n"
table += f"Total: {format(self.get_balance(), '.2f')}"
return table
def create_spend_chart(categories):
names = []
spent = []
p_spent = []
sum_spent = []
for i in categories:
names.append(i.name)
part = 0
for j in i.ledger:
if j["amount"] < 0:
part += j["amount"]
spent.append(round(part, 2))
sum_spent = sum(spent)
for i in spent:
p_spent.append(round(i/sum_spent, 2)//0.01)
result = "Percentage spent by category\n"
print(result)
for x in range(100, 10, 10):
result = result + str(x).rjust(4, " ") + ""
for y in p_spent:
if y >= x:
result = result + " o "
else:
result = result + " "
result = result + " \n"
result = result + " "+ ""*len(p_spent) + "\n"
longest = max(len(x.name) for x in categories)
for x in range(longest):
result = result + " "
for y in categories:
if x< len(y.name):
result = result + " " + y.name[x] + " "
else:
result = result + " "
if x < longest 1:
result = "\n"
return result.rstrip() + " "
Next day.
Could you help me understand this?
Traceback (most recent call last):
File "/home/runner/yaaaamyamazingboilerplatebudgetapp2/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: '\n t ' != 'Percentage spent by category\n100 [383 chars] 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.
Will really appreciate every bit of your help. Thank you!