Build a Budget App Project - Build a Budget App

im having the same issue but free code camp also want let me post on the forum
create_spend_chart should print a different chart representation. Check that all spacing is exact.
it matches the output but doesnt mark as complete

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

    def __str__(self):
        length=len(str(self.name))
        start=(30-length)//2
        header= '*'*start+str(self.name)+'*'*start
        finals=""
        count=0
        for record in self.ledger:
            
            desc=record['description']
            if len(desc)==23:
                desc=record['description']
            elif len(desc)>23:
                desc=record['description'][:23]
            else:
                desc=desc+' '*(23-len(desc))
            
            amts=(record['amount'])
            
            if type(record['amount']) is float:
                amt=(f" {amts}")
            else:
                amt=(f" {amts}.00")
            
            if len(amt)==7:
                amt=amt
            elif len(amt)>7:
                amt=amt[len(amt)-7:]
            else:
                amt=' '*(7-len(record['description']))+str(amt)
            
            spacing=30-len(amt)-len(desc)
        
            finals+= "\n"+ desc +" "*(spacing)+ amt

        fund=str(self.get_balance())
        if type(self.get_balance()) is float:
            total=(f"{fund}")
        else:
            total=(f"{fund}.00")
        total="\nTotal: " + total
            
        return header + finals + total



    def deposit(self,amount,description=''):
        newEntry={"amount": amount, "description": description}
        self.ledger.append(newEntry)

    def get_balance(self):
        balance=0
        for record in self.ledger:
            balance+=record["amount"]
        return balance

    def withdraw(self,amount,description=''):
        withdrawal=False
        newEntry={"amount": -amount, "description": description}
        if self.check_funds(amount):
            self.ledger.append(newEntry)
            return True

        else:
            return False
        
    def check_funds(self,amount):
        if amount>self.get_balance():
            return False
        else:
            return True

    def transfer(self,amount,budget):
        message1="Transfer to "+ budget.name
        if self.check_funds(amount):
            self.withdraw(amount,message1)
            message2="Transfer from "+ self.name
            budget.deposit(amount, message2)
            return True
        else:
            return False

    
def create_spend_chart(categories):
    barchart=""
    barchartL=[]
    percents=[]
    totalSpent=0
    spending=[]
    count=100
    while count>=0:
        if count==100:
            barchartL.append(str(count)+"|")
        elif count!=0:
            barchartL.append(" "+str(count)+"|")
        else:
            barchartL.append("  "+str(count)+"|")
        count-=10

    barchartL.append(' '*4+'-'*(3*len(categories)+1))
    
    for item in categories:
        spent=0
        for amount in item.ledger:
            if amount['amount']<0:
                spent+=amount['amount']
        spending.append(-spent)
    for spent in spending:
        totalSpent+=spent

    for index,item in enumerate(categories):
        percent=round(spending[index]/totalSpent*100,-1)
        percents.append(percent)

    for index,per in enumerate(percents):
        per+=10
        while per>0:
            barchartL[11-int(per/10)]+= ' '*((1+index)*3+1-len(barchartL[11-int(per/10)]))+' o'
            per-=10
        
    categoriesL=[]
    for item in (categories):
        categoriesL.append(item.name)
    
    items=0
    categoriesL.sort(reverse=True)
    for char in categoriesL[0]:
        barchartL.append(' ')

    while items<len(categoriesL):
        expectedLength=5+items*3

        for l in range(len(categoriesL[0])):
            barchartL.append(' '*3)
            
        count=12
        for char in categories[items].name:
            barchartL[count]+=' '*(expectedLength-len(barchartL[count]))+ char 
            count+=1

        items+=1

    for line in barchartL:
        barchart+=line +'\n'
    
    barchart=barchart.strip()

    return ("Percentage spent by category" + "\n"+barchart)

#example
food = Category("Food")
entertainment = Category("Entertainment")
business = Category("Business")    
food.deposit(900, "deposit")
entertainment.deposit(900, "deposit")
business.deposit(900, "deposit")
food.withdraw(105.55)
entertainment.withdraw(33.40)
business.withdraw(10.99)

print(create_spend_chart([business, food,business, food ]))

theres the code

You are missing spaces

AssertionError: 'Perc[25 chars]n100|\n 90|\n 80|\n 70|    o\n 60|    o\n 50| [262 chars]   t' != 
                'Perc[25 chars]n100|          \n 90|          \n 80|         [349 chars] t  '

the first string is yours the second is the expected, you need to have spaces for all the horizontal extension of the graph

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.