Tell us what’s happening:
python-test-evaluator.js:2 AssertionError: 'Perc[226 chars]F E \n u o n \n s o t \n i d[135 chars] t ’ != 'Perc[226 chars]F E \n u o n \n s o t \n i[148 chars] t ’
I am getting this error in the browser console. I have run the code in vscode the code runs perfectly. I couldn’t figure out how 23 and 24 is failing.
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=''):
status = self.check_funds(amount)
if status:
self.ledger.append({'amount': -amount, 'description': description})
return True
else:
return False
def get_balance(self):
balance = 0
for items in self.ledger:
balance += items['amount']
return balance
def transfer(self, amount, other):
status = self.withdraw(amount, f'Transfer to {other.name}')
if status:
other.deposit(amount, f'Transfer from {self.name}')
return True
return False
def check_funds(self, amount):
balance = self.get_balance()
if amount > balance:
return False
return True
def __str__(self):
title = ''
item_desc = ''
str_length = 30-len(self.name)
for i in range(str_length):
if i == str_length/2:
title += self.name
title += "*"
item_desc += title
for items in self.ledger:
amount = f"{items['amount']:.2f}"
description = items['description'][:23]
item_desc += f"\n{description:<23}{amount:>7}"
item_desc += f'\nTotal: {self.get_balance()}'
return item_desc
def create_spend_chart(categories):
title = 'Percentage spent by category\n'
chart = ''
category_withdrawal_amount = []
total_withdrawal_amount = 0
for category in categories:
withdrawal_amount = 0
for items in category.ledger:
if items['amount'] < 0:
withdrawal_amount += abs(items['amount'])
category_withdrawal_amount.append(withdrawal_amount)
total_withdrawal_amount += withdrawal_amount
category_percents = []
for amount in category_withdrawal_amount:
percent = (amount / total_withdrawal_amount) * 100
percent = ((percent) // 10) * 10
category_percents.append(percent)
for level in range(100, -1, -10):
chart += f"{level:>3}|"
for category_percent in category_percents:
if category_percent >= level:
chart += " o "
else:
chart += " "
chart += ' \n'
chart += " " + ("-" * (len(categories) * 3 + 1)) + '\n'
max_length = max(len(category.name) for category in categories)
for i in range(max_length):
chart += " "
for category in categories:
if i < len(category.name):
chart += f" {category.name[i]} "
else:
chart += " "
chart += '\n'
return (title + chart).strip('\n')
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App - Build a Budget App