Tell us what’s happening:
Hi,
I cannot pass test #19. Checked it couple times and all cases tested by me seems to be ok. I don’t see any additional information in F12 console (this particular test does not give any). Also I’m not able to determine exact test case which causing failure.
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 get_balance(self):
return sum([item['amount'] for item in self.ledger])
def withdraws(self):
return sum([abs(item['amount']) for item in self.ledger if item['amount'] < 0])
def withdraw(self, amount, description = ''):
if self.check_funds(amount):
self.ledger.append(
{
'amount' : (-1.0 * amount),
'description' : description
}
)
return True
else:
return False
def transfer(self, amount, category):
if (self.check_funds(amount)):
self.withdraw(amount, f'Transfer to {category.name}')
category.deposit(amount, f'Transfer from {self.name}')
return True
else:
return False
def check_funds(self, amount):
return (amount <= self.get_balance())
def __str__(self):
s = '*' * (15 - len(self.name) // 2)
s += self.name
s += '*' * (30 - len(s))
s += '\n'
for item in self.ledger:
desc = item['description']
desc += ' ' * (23 - len(desc))
s += desc[0:23]
s += f"{item['amount']:.2f}".rjust(7, ' ')
s += '\n'
s+= 'Total: ' + f"{self.get_balance():.2f}"
return s
def create_spend_chart(categories):
s = 'Percentage spent by category\n'
total_spent = sum(c.withdraws() for c in categories)
test = list(((c.withdraws() / total_spent) * 100) for c in categories)
print(test)
ws = list((((c.withdraws() / total_spent) * 100) // 10) * 10 for c in categories)
print(ws)
line_length = 5 + len(categories) * 3
for i in range(100, -1, -10):
line = ''
line += f'{i}|'.rjust(4, ' ')
line += ' '
cidx = 0
for w in ws:
if (w >= i):
line += 'o '
s += line.ljust(line_length, ' ')
s += '\n'
s += ' ' + '-' * (len(categories) * 3 + 1) + ''
max_cat_len = max(len(c.name) for c in categories)
for i in range(max_cat_len):
s += '\n '
for c in categories:
if (len(c.name) > i):
s += c.name[i] + ' '
else:
s += ' '
return s
food = Category('Food')
food.deposit(1000, 'deposit')
food.withdraw(600, 'groceries and dining')
clothing = Category('Clothing')
clothing.deposit(1000, 'deposit')
clothing.withdraw(200, 'clothing and accessories')
auto = Category('Auto')
auto.deposit(1000, 'deposit')
auto.withdraw(100, 'car repairs and gas')
print(create_spend_chart([food, clothing, auto]))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App Project - Build a Budget App Project