Build a Budget App Project - not passing basic tests

Tell us what’s happening:

I think I programmed the class correctly, and the output looks fine, but I am failing practically all the tests (even “depost creates new ledger object”)

Your code so far

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

    def deposit(self,amt,descr):
        self.budget+=amt
        self.ledger.append(tuple([amt,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,src):
        descr="Transfer to %s" % self.name 
        if check_funds(src,amt):
            pass
        if src.withdraw(amt,descr):
            self.deposit(amt,"Transfer from %" % src.name)
            return True
        else:
            return False

    def __str__(self):
        string=''
        title='*'*((30-len(self.name))//2)
        title=title+self.name
        title=title+('*'*(30-len(title)))
        string+=title
        string+='\n'

        for amt,descr in self.ledger:
            string+=f"{descr:23}{amt:7.2f}" 
            string +='\n' 
        string += 'Total: '
        string+=str(self.budget)
        return string

def create_spend_chart(categories):
    return ''


food=Category("food")
food.deposit(5,"spaghetti")
food.deposit(10,"cash")
food.withdraw(3,'dinner')
print(food)

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

1 Like

:balloon:Hello @dasiff !
Welcome to the forum!

Just looking through your code and the challenge specification quickly, it is clear that spacing and the punctuation are not consistent (e.g. ‘’ & “”) throughout. While this may not cause code to fail, it doesn’t help fellow coders to review the code you have written.

One, more important, issue is to do with a method definition relative to the challenge specification. The spec for the deposit method states:

  • A deposit method that accepts an amount and description. If no description is given, it should default to an empty string. The method should append an object to the ledger list in the form of {"amount": amount, "description": description}.

Your deposit method is:

Your “description” parameter has no default value and will, therefore, fail the second test the platform runs on your code.

Without going through the remainder of your code, it might be an idea to scrutinise the object you have written yourself and try to get your code through the gauntlet.

Does this help?

Keep up the good progress!

Happy Coding! :slightly_smiling_face:

1 Like