Tell us what’s happening:
Priblem with accept my solution.
I implimented all methods of class but it shows like I didnt even implement, and I did this graphic it shows all as task need
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App Project - Build a Budget App Project
class Category:
def __init__(self, category):
self.category = category
self.ledger = []
self.amount = 0
def __str__(self):
str_total = ''
title = self.category.center(30, '*')
str_total += title
for item in self.ledger:
if item['description'] == '':
description = ''
amount = f"{item['amount']:.2f}"
else:
description = item['description']
amount = f"{item['amount']:.2f}"
# create string from every item
str_total += f'\n{description[:23]:<{29 - len(amount)}} {amount}'
str_total += f'\nTotal: {self.amount:.2f}'
return str_total
def deposit(self, amount, description=''):
if description == '':
description = ''
self.ledger.append({'amount': amount, 'description': description})
self.amount += amount
def withdraw(self, amount, description = ''):
if self.check_funds(amount):
if description == '':
description = ''
spend = -(amount)
self.amount += spend
self.ledger.append({'amount': spend, 'description': description})
print(self.get_balance())
return True
else:
return False
def transfer(self, amount, target):
if self.check_funds(amount):
target.deposit(amount, f'Transfer from {self.category}')
self.withdraw(amount, f'Transfer to {target.category}')
return True
else:
return False
def get_balance(self):
return str(f'{self.amount:.2f}')
def check_funds(self, amount_new):
if self.amount < amount_new:
return False
return True
def create_spend_chart(categories):
amount_spent = []
for cat in categories:
spend = 0
for item in cat.ledger:
if item['amount'] < 0:
spend += abs(item["amount"])
amount_spent.append(round(spend, 2))
total = round(sum(amount_spent, 2))
percentage_spent = list(map(lambda amount: int((amount / total) * 100), amount_spent))
list_cat = categories
percents_for_spend = 'Percentage spent by category\n'
for i in range(100, -1, -10):
percents_for_spend += f"{str(i) + '|':>4}"
for percent in percentage_spent:
if percent >= i:
percents_for_spend += ' o '
else:
percents_for_spend += " "
if i != 0:
percents_for_spend += "\n"
else:
continue
percents_for_spend += len_space(list_cat) + '\n'
category_names = [category.category for category in categories]
len_max = len_categories(list_cat)
all_names = [name.ljust(len_max) for name in category_names]
for i in range(len_max):
percents_for_spend += ' ' * 5
for name in all_names:
percents_for_spend += name[i] + " "
percents_for_spend += '\n'
return percents_for_spend
def len_space(list_cat):
return f"\n{' ' * 4}{'-' * (len(list_cat)*3)}"
def len_categories(list_cat):
len_biggest = 0
for i in range(len(list_cat)):
if len_biggest < len(list_cat[i].category):
len_biggest = len(list_cat[i].category)
return len_biggest
def checking_str_len(str_check):
if len(str_check) == 3:
return ''
if len(str_check) == 2:
return ' '
if len(str_check) == 1:
return ' '
ILM
March 13, 2025, 10:32pm
2
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
ILM
March 13, 2025, 10:36pm
3
question, why are you returning a string?
The description is
A get_balance
method that returns the current balance of the budget category based on the deposits and withdrawals that have occurred.
with get balance changed, it was because I was thinking about balance that needs in form 1000.00
Last functinon working as it needs, if I compare with task, but it dont take decision
Troubleshooting is a process of proving each step. Gather evidence.
Look at the first failed test and use print()
to output a variable in your code to prove it’s meeting the requirements.
1 Like
ILM
March 13, 2025, 11:25pm
8
you will need to have it as a number
the tests are using get_balance
to check if the other functions are working correctly, and if you give back a string instead of a number, it will not match
1 Like
I changed this, now this problem solved but this graphic what it have to create shows mistake but it makes as I need
ILM
March 13, 2025, 11:32pm
10
share your updated code
you can open the browser console with F12 to see a more detailed output from the tests
1 Like
ILM
March 13, 2025, 11:35pm
12
that is not your code
also did you check the browser console?
1 Like
ILM
March 13, 2025, 11:37pm
13
you have an extra <
at the beginning and an extra >
at the end of your code, you should not have those
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
1 Like
class Category:
def __init__(self, category):
self.category = category
self.ledger = []
self.amount = 0
def __str__(self):
str_total = ''
title = self.category.center(30, '*')
str_total += title
for item in self.ledger:
if item['description'] == '':
description = ''
amount = f"{item['amount']:.2f}"
else:
description = item['description']
amount = f"{item['amount']:.2f}"
# create string from every item
str_total += f'\n{description[:23]:<{29 - len(amount)}} {amount}'
str_total += f'\nTotal: {self.amount:.2f}'
return str_total
def deposit(self, amount, description=''):
if description == '':
description = ''
self.ledger.append({'amount': amount, 'description': description})
self.amount += amount
def withdraw(self, amount, description = ''):
if self.check_funds(amount):
if description == '':
description = ''
spend = -(amount)
class Category:
def __init__(self, category):
self.category = category
self.ledger = []
self.amount = 0
def __str__(self):
str_total = ''
title = self.category.center(30, '*')
str_total += title
for item in self.ledger:
if item['description'] == '':
description = ''
amount = f"{item['amount']:.2f}"
else:
description = item['description']
amount = f"{item['amount']:.2f}"
# create string from every item
str_total += f'\n{description[:23]:<{29 - len(amount)}} {amount}'
str_total += f'\nTotal: {self.amount:.2f}'
return str_total
def deposit(self, amount, description=''):
if description == '':
description = ''
self.ledger.append({'amount': amount, 'description': description})
self.amount += amount
def withdraw(self, amount, description=''):
if self.check_funds(amount):
if description == '':
description = ''
spend = -(amount)
self.amount += spend
self.ledger.append({'amount': spend, 'description': description})
# print(self.get_balance())
return True
else:
return False
def transfer(self, amount, target):
if self.check_funds(amount):
target.deposit(amount, f'Transfer from {self.category}')
self.withdraw(amount, f'Transfer to {target.category}')
return True
else:
return False
def get_balance(self):
return self.amount
def check_funds(self, amount_new):
if self.amount < amount_new:
return False
return True
def create_spend_chart(categories):
amount_spent = []
for cat in categories:
spend = 0
for item in cat.ledger:
if item['amount'] < 0:
spend += abs(item["amount"])
amount_spent.append(round(spend, 2))
total = round(sum(amount_spent, 2))
percentage_spent = list(map(lambda amount: int((amount / total) * 100), amount_spent))
list_cat = categories
percents_for_spend = 'Percentage spent by category\n'
for i in range(100, -1, -10):
percents_for_spend += f"{str(i) + '|':>4}"
for percent in percentage_spent:
if percent >= i:
percents_for_spend += ' o '
else:
percents_for_spend += " "
if i != 0:
percents_for_spend += " \n"
else:
percents_for_spend += " "
continue
percents_for_spend += len_space(list_cat)
category_names = [category.category for category in categories]
len_max = len_categories(list_cat)
all_names = [name.ljust(len_max) for name in category_names]
for i in range(len_max):
percents_for_spend += '\n' + ' ' * 5
for name in all_names:
percents_for_spend += name[i] + " "
return percents_for_spend
def len_space(list_cat):
return f"\n{' ' * 4}{'-' * ((len(list_cat) * 3) + 1)}"
def len_categories(list_cat):
len_biggest = 0
for i in range(len(list_cat)):
if len_biggest < len(list_cat[i].category):
len_biggest = len(list_cat[i].category)
return len_biggest
def checking_str_len(str_check):
if len(str_check) == 3:
return ''
if len(str_check) == 2:
return ' '
if len(str_check) == 1:
return ' '
food = Category('Food')
food.deposit(1000, 'deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
clothing.withdraw(20.15, 'Cosas')
print(create_spend_chart([food, clothing]))
ILM
March 13, 2025, 11:39pm
15
the browser console output is really useful
AssertionError: 'Perc[35 chars] \n 90| \n 80| \n 70|[350 chars] t '
!= 'Perc[35 chars] \n 90| \n 80| \n 70| [339 chars] t '
here it shows the difference between your code and the expected code in line
1 Like
ILM
March 13, 2025, 11:56pm
17
in the console
run the tests with the console open and you will see a more detailed output
1 Like
Now it shows the same(((
I’m done thank YOU very much!!!
1 Like