Basta Fazoolin’ Project Link: Basta Fazoolin’ Link
Topic: Classes - Instance Variables, Methods
Hello, I am having trouble understanding the instance variable concept. Please look at the follow code from the Basta Fazoolin’ project:
def calculate_bill(self, purchased_items):
bill= 0
for purchased_item in purhcased_items:
if purchased_item in self.items:
bill += self.items[purchased_item]
return bill
***Menu dictionaries are below and outside of the dictionary
Included inside of the method calculate_bill for the menu class, there is an if statement. The purpose of this if statement is to check if the item is on one of the menus. However, I am confused how Python knows how to check the menu dictionaries that are listed outside of the class method by checking the instance variable self.items. The “items” variable is not used anywhere else in the project. Could someone please explain how python knows how to check the menus? I am also confused by the line: bill += self.items[purchased_item]. Can someone explain the indexing on this for me?