Tell us what’s happening:
All testcases pass except testcase 19. The error I get is:
“The height of each bar on the create_spend_chart chart should be rounded down to the nearest 10.”
I think I calculated the percenteges correctly, so I don’t know where the problem is.
In the console I get the following error:
{message: ‘Unspecified AssertionError’, showDiff: false, actual: null, expected: undefined, stack: ‘AssertionError: Unspecified AssertionError\n at …t-runner/9.0.1/python-test-evaluator.js:2:157407)’}
Need hlp
Your code so far
class Category():
total_spendings = 0
def \__init_\_(self, name):
self.name = name
self.ledger = \[\]
self.balance = 0
self.spendings = 0
def check_funds(self, amount):
if amount <= self.balance:
return True
else:
return False
def deposit(self, amount, description=''):
transaction = {'amount': amount, 'description': description}
#if not description:
\# transaction.'description' = ''
#else:
\# transaction.'description' = description
self.balance += amount
self.ledger.append(transaction)
def withdraw(self, amount, description=''):
if not self.check_funds(amount):
return False
transaction = {'amount': -amount, 'description': description}
#if not description:
\# transaction.'description' = ''
#else:
\# transaction.'description' = description
self.ledger.append(transaction)
self.balance -= amount
self.spendings += amount
Category.total_spendings += amount
return True
def get_balance(self):
return self.balance
def transfer(self, amount, category):
descr_source = f'Transfer to {category.name}'
descr_dest = f'Transfer from {self.name}'
#if not check_funds(amount)
\# return False
if self.withdraw(amount, descr_source):
category.deposit(amount, descr_dest)
#self.spendings += amount
return True
return False
def \__str_\_(self):
title = self.name.center(30,'\*')
output = f'{title}'
for trans in self.ledger:
length_descr = min(len(trans\['description'\]), 23)
output += f"\\n{trans\['description'\]\[:length_descr\]:<23}{trans\['amount'\]:>7.2f}"
output += f'\\nTotal: {self.balance}'
return output
def create_spend_chart(categories):
print("total spendings ", Category.total_spendings)
percentage_each = {}
for category in categories:
percentage_each[category] = category.spendings / Category.total_spendings * 100 if Category.total_spendings >0 else 0
print(f’{category.name}: {percentage_each[category]} %‘)
#create vertical string:
string = “Percentage spent by category”
for percentage in range(100,-1,-10):
string += f’\n{str(percentage):>3}| ’
for category in categories:
if percentage_each[category] >= percentage:
string += "o "
else:
string += " "
#make underscore line
string += f’\n ’ + ‘—’ * len(categories) + ‘-’
#make vertical category names
maxCategoryNameLength = max(len(category.name) for category in categories)
for i in range(maxCategoryNameLength):
string += '\\n '
for category in categories:
if i < len(category.name):
string += f'{category.name\[i\]} '
else:
string += ' '
return string
def main():
food = Category(‘Food’)
food.deposit(1000, ‘initial deposit’)
food.withdraw(10.15, ‘groceries’)
food.withdraw(15.89, ‘restaurant and more food for dessert’)
clothing = Category(‘Clothing’)
food.transfer(50, clothing)
clothing.deposit(20, ‘toale’)
clothing.deposit(500, ‘toale multe’)
clothing.withdraw(30,‘pulover’)
clothing.withdraw(100, ‘geaca’)
clothing.withdraw(300, ‘ski’)
auto = Category(‘Auto’)
auto.deposit(2000, ‘intretinere’)
auto.withdraw(100, ‘bec far’)
auto.withdraw(200, ‘cauciuc’)
auto.transfer(100,food)
print(food)
print(clothing)
print(auto)
print(create_spend_chart([food, clothing, auto]))
if _name_ == ‘_main_’:
main()
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App - Build a Budget App

