# Budget App create\_spend\_chart error,not passing

**URL:** <https://forum.freecodecamp.org/t/budget-app-create-spend-chart-error-not-passing/419434>\
**Category:** General\
**Created:** [September 7, 2020, 6:34pm UTC](https://forum.freecodecamp.org/t/budget-app-create-spend-chart-error-not-passing/419434 "2020-09-07T18:34:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryanf1031](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bryanf1031/32/134575_2.png) [@bryanf1031](https://forum.freecodecamp.org/u/bryanf1031)\
**Post date:** [September 7, 2020, 6:34pm UTC](https://forum.freecodecamp.org/t/budget-app-create-spend-chart-error-not-passing/419434/1 "2020-09-07T18:34:11Z")

</div>

So, here is my code:  
class Category:  
def **init** (self,name):  
self.name = name  
self.ledger =

```
def deposit(self,amount, description=""):
    self.ledger.append({"amount":amount, "description":description})
    return self.ledger
    
    
def check_funds(self,amount):
    total = 0
    for i in range(len(self.ledger)):
        total += self.ledger[i]['amount']
    if total >= amount:
        return True
    else:
        return False
    
def withdraw(self,amount, description=""):
     
     if Category.check_funds(self,amount) == True:
        self.ledger.append({"amount":-amount, "description":description})
        return True
     else:
        return False
    
def get_balance(self):
    total = 0
    for i in range(len(self.ledger)):
        total += self.ledger[i]['amount']
        
    return total #unformated
    #return "{:.2f}".format(total)

    
def transfer(self,amount,destination):
    self.destination = destination
    
    #make new withdraw instructions
    if Category.check_funds(self,amount) == True:
        #if return is True, append to ledger
        self.ledger.append({"amount":-amount, "description":"Transfer to "+destination.name})
        #make new deposit instructions
        destination.ledger.append({"amount":amount, "description":"Transfer from "+self.name})
        return True
    else:
        return False
    
    
    
    
def __str__ (self):#amount, description?
    
    Formatted = "{:*^30}"
    title= (Formatted.format(self.name)) +'\n'
    
    
    #get_balance and store in total_balance variable
    total_balance = Category.get_balance(self)
    #total_balance = "{:.2f}".format(total_balance)
    #convert to decimal with two digits after period, if not already a decimal
    items = ''
  
    self.items_lst = []
    #print(self.ledger[0].values())
    for i in range(len(self.ledger)):
        
        
        if len(str("{:.2f}".format(self.ledger[i]['amount']))) > 7:
            items += self.ledger[i]['description'][:22]+str("{:.2f}".format(self.ledger[i]['amount'])[:8]).rjust(30-(len(self.ledger[i]['description'][:23])))+'\n'
        
        else:
            items += self.ledger[i]['description'][:23]+str("{:.2f}".format(self.ledger[i]['amount'])[:7]).rjust(30-(len(self.ledger[i]['description'][:23])))+'\n'
    return title + items+"Total: " + str(total_balance)

```

def create\_spend\_chart(categories):  
category\_dict = dict()  
for items in categories:  
total = 0  
for pairs in items.ledger:  
for index in pairs:  
if index == ‘amount’:  
if pairs[index] \< 0:  
pairs[index] = -pairs[index]  
total += pairs[index]  
category\_dict[items.name] = total  
spending\_total = 0  
for index in category\_dict:  
spending\_total += category\_dict[index]  
percents\_dict = dict()  
for index in category\_dict:  
percent = (category\_dict[index] / spending\_total) \* 100  
percent = “{:.0f}”.format(percent)  
percent = int(percent)  
#percent = round(percent/10)\*10  
percent = (percent//10)\*10  
percents\_dict[index] = percent

```
#print(percents_dict)
percents_lst = list()
for i in percents_dict:
    percents_lst.append(percents_dict[i])

final_percent_lst = list()
percents = ['100|', '90|', '80|','70|','60|','50|','40|','30|','20|','10|','0|']
final_percent_lst.append(percents)
for percent in percents_lst:
    percent_lst = [' '] * 11

    for i in range(len(percent_lst[0:percent//10 + 1])):
        percent_lst[i] = 'o'
    percent_lst = percent_lst[::-1] #reverse each list
    final_percent_lst.append(percent_lst)

vertical_axis = list(zip(*final_percent_lst))

max_category_length = list() 
category_name_lst = list()

for category in percents_dict:
    max_category_length.append(len(category))
for cat_name in percents_dict:
    category_name_lst.append(cat_name)

full_category_name_letter_lst = list()
for category in category_name_lst:
    full_category_name_letter_lst.append(list(category))  

final_category_letter_lst = list()
for name in full_category_name_letter_lst:    
    category_letters = [' '] * max(max_category_length)
    category_letters_lst = name + category_letters[:max(max_category_length) - len(name)]
    final_category_letter_lst.append(category_letters_lst) 

    
horizontal_axis = list(zip(*final_category_letter_lst))
vertical = ''
horizontal = ''
bottom_line = ''
title = str('Percentage spent by category') + '\n'
if len(percents_lst) == 1:
    for y in vertical_axis:
        vertical += str(y[0]).rjust(4)+str(y[1]).rjust(2)+' '+'\n'
    if y[0] == '0|':
        bottom_line = str('-' * (len(y)+2)).rjust(8)+ '\n'
    for x in horizontal_axis:
        horizontal += str(x[0]).rjust(6) +' ' + '\n'
    return title + vertical + bottom_line + horizontal
if len(percents_lst) == 2:
    for y in vertical_axis:
        vertical += str(y[0]).rjust(4)+str(y[1]).rjust(2)+str(y[2]).rjust(2)+' '+'\n'
    if y[0] == '0|':
        bottom_line = str('-' * (len(y)+3)).rjust(10)+ '\n'
    for x in horizontal_axis:
        horizontal += str(x[0]).rjust(6)+str(x[1]).rjust(2) +' ' +'\n'
    return title + vertical + bottom_line + horizontal
if len(percents_lst) == 3:
    for y in vertical_axis:
        vertical += str(y[0]).rjust(4)+str(y[1]).rjust(2)+str(y[2]).rjust(3)+str(y[3]).rjust(3)+' '+'\n'
    if y[0] == '0|':
        bottom_line = str('-' * (len(y)+6)).rjust(14)+ '\n'
    for x in horizontal_axis:
        horizontal += str(x[0]).rjust(6)+str(x[1]).rjust(3)+str(x[2]).rjust(3) +' ' +'\n'
    return title + vertical + bottom_line + horizontal
if len(percents_lst) >= 4:
    for y in vertical_axis:
        vertical += str(y[0]).rjust(4)+str(y[1]).rjust(2)+str(y[2]).rjust(2)+str(y[3]).rjust(2)+str(y[4]).rjust(2) +' '+'\n'
    if y[0] == '0|':
        bottom_line = str('-' * (len(y)+4)).rjust(14)+ '\n'
    for x in horizontal_axis:
        horizontal += str(x[0]).rjust(6)+str(x[1]).rjust(2)+str(x[2]).rjust(2)+str(x[3]).rjust(2)+' ' +'\n'
    return title + vertical + bottom_line + horizontal

```

I have enclosed a screen shot of the Repl.it error:

 ![replit_error](https://global.discourse-cdn.com/freecodecamp/original/3X/5/1/51e2ea71f30606a987eb3167a68366139a9c2dad.jpeg)  
I don’t know what the error is telling me. Please help!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:41pm UTC](https://forum.freecodecamp.org/t/budget-app-create-spend-chart-error-not-passing/419434/2 "2021-06-01T18:41:19Z")

</div>


