Build a Budget App - Build a Budget App Test 7

Tell us what’s happening:

Not sure why I’m stumped so hard on test 7, must be misinterpreting something because from my test prints on the ledger in the target category, the methods up to here all work as expected. Yet despite the console showing the new ledger added, I’m still getting that the transfer method isnt creating one. Appreciate some help on this!
Also it’s driving me and from the looks of it, many others crazy that there are so few exercises along the way and hints are almost comically and excessively vague.

Your code so far

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

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

    def withdraw(self,amount,description=''):
        if self.check_funds(amount):
            self.balance+=amount*-1
            self.ledger.append({'amount': amount*-1, 'description': description})
            return True
        else:
            return False

    def get_balance(self):
        return self.balance
    
    def transfer(self,amount,destination):
        if self.check_funds(amount):
            self.withdraw(amount,description=f'Transfer to {destination}')
            destination.deposit(amount,f'Transfer from {self.name}')
                     
            return True
        else:
            return False
            
   
    def check_funds(self,amount):
        if amount>self.balance:
            return False
        else:
            return True


def create_spend_chart(categories):
    pass


food = Category('Food')
food.deposit(1000, 'initial deposit')
print(food.get_balance())

clothes = Category('Clothes')
clothes.deposit(500, 'initial deposit')
print(clothes.get_balance())

food.transfer(100,clothes)
print(food.get_balance())
print(clothes.get_balance())

print(clothes.ledger)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0

Challenge Information:

Build a Budget App - Build a Budget App

Bad Response, Disregard.

What is destination? you do not have it defined anywhere. The program has no idea what you want to do with it.

  • A transfer method that accepts an amount and another Category instance, withdraws the amount with description Transfer to [Destination], deposits it into the other category with description Transfer from [Source], where [Destination] and [Source] should be replaced by the name of destination and source categories. The method should return True when the transfer is successful, and False otherwise.

Also you should not have destination in the def transfer(). The user story defines what should be included there.

Changing {destination} to {destination.name} in ‘self.withdraw(amount,f’Transfer to {destination.name}’ worked in the end and allowed me to succeed in Test 7.. it really boiled down to a small oversight on my end.

Though out of curiosity, how would I define the destination anywhere else? I’ve referred to so many entries here on the forum and everyone seems to be using my similar method of including the destination category as an extra parameter. In my understanding, I don’t have to define it at all since i will be putting in a seperate category when calling it as per my testing at the bottom with food.transfer(100,clothes) I’m not being snarky btw, I spent some time thinking about it and I can’t seem to come up with an answer.

1 Like

I have mine defined like this. Although I am still working down the project I have passed every tested element thus far i think i have 20, 21, and 22 still not passing. I have not finished writing it yet though I’m working on it now actually

Spoiler
def transfer(self, amount, Category):
    Source = self.name
    Destination = Category.name

Oh, no worries but thanks for the help. In your instance though, isn’t the parameter ‘Category’ basically just different in name from simply ‘destination’?

1 Like

I just didn’t put it in the arguments of the def transfer() function but otherwise yeah.

Ah, gotcha, sorry if I come off as pedantic but I wanna make sure I’m not missing on anything :folded_hands:

1 Like

wait a minute lmao yeah you are right I am stupid lol

all good man I am pretty new with this also. You are 100% correct though. and the only reason mine was different is because i assigned the variable destination = Category.name instead of using destination.name it in the self.withdraw() call

were you able to pass the tests all the way up to 11 with the way you wrote the code out? Just out of curiosity.

Yeap, up to 15! I can finally move on to the printing part. Before figuring this post’s topic out, I had everything except test 7

1 Like

Awesome man if you need anymore help let me know. I struggled with getting the chart created for quite a while so if I can pass along any relevant knowledge i’d be happy to help.

1 Like