Build a Budget App Project - Build a Budget App Project

Tell us what’s happening:

It is telling me that something wrong with my spacing on the chart but I don’t know what!

Your code so far

class Category:
    def __init__(self,name):
        self.ledger=[]
        self.budget=0
        self.name=name
        self.percent=0

    def deposit(self,amt,descr=''):
        self.budget+=amt
        self.ledger.append({"amount":amt, "description":descr})

    def withdraw(self,amt, descr=''):
        if self.check_funds(amt):
            self.deposit(amt*(-1),descr)
            return True
        else:
            return False

    def get_balance(self):
        return self.budget

    def check_funds(self, amt):
        return self.budget>=amt


    def transfer(self,amt,dest): #xfer out
        descr="Transfer to %s" % dest.name 
        if self.check_funds(amt):
            self.budget-=amt
            self.ledger.append({"amount":amt*(-1), "description":descr})
            dest.deposit(amt,f"Transfer from {self.name}")
            return True
        else:
            return False
        
        

    def __str__(self):
        string=''
        title=self.name.center(30,'*')
        string+=title
        string+='\n'

        for item in self.ledger:
            descr=item["description"]
            amt=item["amount"]
            string+=f'{descr[0:23]:23}{amt:7.2f}' 
            string +='\n' 
        string += 'Total: '
        string+=str(self.budget)
        return string

def create_spend_chart(categories):
    array=['']*13
    array[0]='Percentage spent by category'
    array[1]='100| '
    for i in range(2,11):
        array[i]=(' '+str(110-10*i)+'| ')
    array[11]='  0| '
    array[12]='    '
    array[12]+='---'*(len(categories))+'-'
    print(len(array))
    maxname=0
    for cat in categories:
        maxname=max(maxname,len(cat.name))
    for i in range(maxname):
        array.append('     ')

    totspent=0
    for cat in categories:
        spent=0
        for item in cat.ledger:
            if ('Transfer' not in item["description"]) and (item["amount"]<0):
                spent-=item["amount"]
        cat.percent=spent
        totspent+=spent
    for cat in categories:
            cat.percent=10*cat.percent/totspent
    for cat in categories:
            print(cat.name,' ',cat.percent)
    #sort categories by cat.percent
    categories.sort(reverse=True,key=lambda cat:cat.percent)
    for i in range(11):
        row=11-i
        for cat in categories:
            if (cat.percent)>=(i):
                array[row]+='o  '
            else:
                array[row]+='   '

    
    array[13]='     '            
    for i in range(maxname):
        for cat in categories:
            if len(cat.name)>i:
                array[13+i]+=(''+cat.name[i]+'  ')
            else:
                array[13+i]+='   '
    
    print('\n'.join(array))        
    return '\n'.join(array)


food = Category("Food")
food.deposit(60, "deposit")
food.withdraw(60, "groceries")

clothing = Category("Clothing")
clothing.deposit(20, "clothing")
clothing.withdraw(20, "clothing")

auto=Category("Auto")
auto.deposit(60,"car")
auto.withdraw(10,"car")

print(food)
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/124.0.0.0 Safari/537.36

Challenge Information:

Build a Budget App Project - Build a Budget App Project

If you open the devtools (f12 button) and check the console output there will be a more detailed error message.

your columns are in the wrong order, put them in the order they are given in