Scientific Computing with Python Projects - Budget App

Hello guys,
I am struggling with budget app from scientific computing with python projects.
I am still working on the cose since the second part of the task (create spending chart) is quite crazy in my opinion :smiley:

In any case, I have an annoying error in the class itself: in the transfer method I don’t manage to transfer the money to the given category.
It keeps telling me that i cannot call the deposit method on a string (category), but how can i make it understand that category is a Category object and not only a string?
I guess it’s quite obvious but i can’t see it.
Is it a problem related to how i defined/initialized the class Category? Or i am making some sintax error in the transfer method itself?

Here is my code:

code

Thanks a lot for you help and suggestions!

Your browser information:

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

Challenge: Scientific Computing with Python Projects - Budget App

Link to the challenge:

1 Like

There was a similar question posted recently with the same problem. You really need to post the error message generated:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    import budget
  File "/home/runner/boilerplate-budget-app-2/budget.py", line 88, in <module>
    A.transfer(200, "Clothing")
  File "/home/runner/boilerplate-budget-app-2/budget.py", line 26, in transfer
    self.withdraw(amount, "Transfer to " + category.name)
AttributeError: 'str' object has no attribute 'name'

Your code here

    A.transfer(200, "Clothing")

is calling the transfer() method with a string as the category argument. Your transfer() method as you’ve coded it

    def transfer(self, amount, category):
        if self.check_funds(amount):
            self.withdraw(amount, "Transfer to " + category.name)
            category.deposit(amount, "Transfer from " + self.name)
            print("Transfer successful!")
            return True
        else:
            print("Transfer failed due to lack of money!")
            return False

is treating category as a Category object but since you are passing in a string, it generates this error:

AttributeError: 'str' object has no attribute 'name'
1 Like