Tell us what’s happening:
I’ve spent alot of time on this. When i run my code in VS code i get the same exact spacing as the example provided, ive checked line by line. I also tested and my final_chart is a string which the test asks for.
The F12 test is confusing but I’m basically failing step 17 and up which doesn’t make sense. F12 tells me this:
{message: ‘Unspecified AssertionError’, showDiff: false, actual: null, expected: undefined, stack: ‘AssertionError: Unspecified AssertionError\n at …t-runner/9.0.0/python-test-evaluator.js:2:156979)’
In VS code my output looks like this:
class Category():
def __init__(self,name):
self.name = name
self.ledger = []
self.running_total = 0
self.total_spend = 0
def __str__(self):
print(self.ledger)
pass
#### ALLL CODE NEEDS TO BE UPDATED TO APPEND DICTIONARYS NOT FSTRINGs
def deposit(self,amount,description=''):
deposit_amount = {'amount':amount, 'description': description}
self.ledger.append(deposit_amount)
self.running_total = self.running_total + amount
def withdraw(self,amount,description=''):
if self.check_funds(amount):
amount = -amount
withdrawl_amount = {'amount': amount, 'description': description}
self.ledger.append(withdrawl_amount)
self.running_total = self.running_total + amount
self.total_spend = self.total_spend + amount
return True if self.running_total >=0 else False
else:
return False
def get_balance(self):
return self.running_total
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 if self.running_total >=0 else False
else:
return False
def check_funds(self,amount):
if amount > self.running_total:
return False
else:
return True
#how can i pull out the objects
def __str__(self):
receipt_star = int((30 - len(self.name)) / 2)
star_ = '*'
title_ = (f'{receipt_star * star_}{self.name}{receipt_star * star_}\n'
)
output = title_
for item in self.ledger:
description = item['description']
amount = item['amount']
amount = float(amount)
output+= f'{description.ljust(23)[:23]}{amount:>7.2f}\n'
output+= f'Total: {float(self.running_total):.2f}'
return output
def create_spend_chart(*categories):
title = 'Percentage spent by category\n'
final_chart=''
final_chart +=title
cat_dict = {}
sum_total = 0
marker_ = 'o'
precentages_ = range(100,0,-10)
#all spend stored in dict by cat
for category in categories:
Category(category)
cat_dict[category.name] = abs(category.total_spend)
#calculate sum total for each cat
for key, value in cat_dict.items():
value = abs(int(value))
sum_total = sum_total + value
#replace the value with new value represented as a whole number
for key, value in cat_dict.items():
cat_dict[key] = (value/sum_total)*100
#convert the dict value to % of total?
#for key,value in cat_dict:
for x in range(100,-10,-10):
row_marker = ''
final_chart+= (f'{x:>3}|')
#adding the dots
for key,value in cat_dict.items():
value = abs(value)
row_marker += f" {marker_ if value >= x else ' '} "
final_chart+=row_marker + '\n'
## print the footer
footer_ = ' '
for key in cat_dict:
footer_ += f"---"
final_chart+=footer_+'-\n'
#print category letters
footer_list = []
length_ = 3
for key,value in cat_dict.items():
footer_list.append(key)
footer_length = max(len(word) for word in footer_list)
spaces_ = " "
footer_cat = ''
z = len(footer_list)+1
for num in range(0,footer_length+1):
z = z-1
footer_cat = ' '
for cat in footer_list:
if num < len(cat):
y = list(cat)
y = y[num]
footer_cat+= f'{y:>3}'
else:
footer_cat+=' '
final_chart += f'{footer_cat}\n'
return final_chart
food = Category('Food')
food.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(10.15, 'restaurant and more food for dessert')
food.withdraw(10000,'fraud')
clothing = Category('Clothing')
clothing.deposit(1000,'Money')
clothing.withdraw(500,'FUN')
food.transfer(50, clothing)
video_games = Category('Video Games')
video_games.deposit(1000,"paycheck")
video_games.withdraw(500,'ZELDA')
video_games.withdraw(450,'WOW')
test_ = create_spend_chart(food,clothing,video_games)
#testing my three instances
print(test_)
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/146.0.0.0 Safari/537.36
Challenge Information:
Build a Budget App - Build a Budget App

