Build a Budget App Project - Build a Budget App Project

Tell us what’s happening:

When i use print there is some weird error with the printing. for example is i write
print(‘*’,end=‘’)
it prints
’ * [object Object]’
the [object Object] is not a problem when i use another IDE (namely VS code). Please do let me know if there is anything i can do to fix this error.
this error is showing both in and out of the class and even on a different project as far as i can see. This has never happened to me so I am quite confused. I have finished the project as it says to do in the Instructions as of now

This is a photo of the IDE on the website. It shows correct on VS code (the budget part)

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/128.0.0.0 Safari/537.36

Challenge Information:

Build a Budget App Project - Build a Budget App Project

My code so far :

import math

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

    
    def get_balance(self):
        am=0
        for i in self.ledger : 
            am+=i['amount']
        return am

    def check_funds(self,amt):
        if amt>self.get_balance() : 
            return False
        return True
    
    def __str__(self) : 
        length=len(self.category)
        for i in range(15-length//2) :
            print('*', end='')
        print(self.category,end='')
        if length%2==0 : 
            print('*',end='')
        for i in range(14-length//2) : 
            print('*',end='')
        print(" ")
        for l in self.ledger : 
            des=' '
            if l['description']=='deposit' : 
                des='initial deposit'
            else :
                des=l['description']
            amt=0
            a=0
            if l['amount']<0:
                amt=math.ceil(math.log(-l['amount'],10))+1
                a=-l['amount']
            else :
                amt=math.ceil(math.log(l['amount'],10))
                a=l['amount']
            if 10**math.ceil(math.log(a,10))-a==0 : 
                amt+=1
            if len(des)>26-amt : 
                des=des[:26-amt]+""
            print(des,end='')
            for i in range(27-len(des)-amt) :
                print(' ',end='')
            print('{:.2f}'.format(l['amount']))
        print("Total:",'{:.2f}'.format(self.get_balance()),'\n\n')
        return ""

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

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

    def transfer(self,amt,bud):
        if self.check_funds(amt) : 
            self.withdraw(amt,f'Transfer to {bud.category}')
            bud.deposit(amt,f'Transfer from {self.category}')
            return True
        return False
def expendeture(obj) : 
    lst=obj.ledger
    amt=0
    for l in lst : 
        if l['amount']<0 : 
            amt-=l['amount']
    return amt
def create_spend_chart(categories):
    cat=[]
    l=0
    for category in categories:
        cat.append(expendeture(category))
        if l<len(category.category) : 
            l=len(category.category)
    cat = [round(100*i/sum(cat)) for i in cat]
    print('Percentage spent by category')
    for i in range(100,-1,-10) : 
        if i!=100 :
            print(' ',end='')
        if i==0 : 
            print(' ',end='')
        print(i,'| ',sep='',end='')
        for index,category in enumerate(categories) : 
            if cat[index]>=i : 
                print('o  ',end='') 
            else : 
                print('   ',end='')
        print('  ')
    print('    -',end='')
    for i in range(len(cat)) : 
        print('---',end='')
    print('')
    for i in range(l) : 
        print('     ',end='')
        for j in range(len(categories)) : 
            if len(categories[j].category)>i : 
                print(categories[j].category[i],end='  ')
            else :
                print('   ',end='')
        print('')

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)
auto = Category('Auto')
auto.deposit(400, 'deposit')
auto.withdraw(60, 'groceries')
auto.withdraw(80, 'restaurant and more food for dessert')
clothing.deposit(5000, 'deposit')
clothing.withdraw(800, 'tshirt')
category=[food,auto,clothing]
print(food,auto,clothing)
create_spend_chart(category)

The FCC editor doesn’t allow you to use these second arguments using print.

You don’t need them for this project however, since:

It should return a string that is a bar chart.

Your function should return a single string, and not print anything. If you want to print the result you can call it like this:

print(create_spend_chart([food, clothing,auto]))