Budget app: Question on Class members and structure

Tell us what’s happening:
During this project we are doing all our code in the budget.py file. Here we have class definition (together with the diferent methods) and on the same “level” with the class we are proposed to create another function:
class Category:
def deposit(self, amount, description=""):

def create_spend_chart(categories):

Could you please help to understand if last function is related and is the part of class?
Because it little bit confusing me that on create_spend_chart call from
print(create_spend_chart([food, clothing, auto]))
I have received result which shows me data from class definition.
Please point me to helpful reading on this question.

Your code so far
def create_spend_chart(categories):
list_of_cat = categories
length = len(categories)
print(length, list_of_cat, list_of_cat[0])

and result of print(create_spend_chart([food, clothing, auto])) is:

3 [<budget.Category object at 0x7f1bb6d76a30>, <budget.Category object at 0x7f1bb6c803d0>, <budget.Category object at 0x7f1bb6c801c0>] Food
initial deposit 1000.00
groceries -10.15
restaurant and more foo -15.89
Transfer to Clothing -50.00
Total: 923.96

Your browser information:

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

Challenge: Budget App

Link to the challenge:

create_spend_chart function is not a part of class. Remember python uses indentation to distinguish blocks of code that go together, as create_spend_chart and Category class are indented the same way, first one isn’t the part of latter.

This doesn’t mean create_spend_chart cannot have Category class instances passed as arguments and be expected to do something with them.

Got it… Thanks a lot, I forgot that [food, clothing, auto] it is not a list of string type objects but list of instances of Category instances…

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