I see this question has been asked before in different variations, but I feel as though I have implemented the feedback I have seen in those threads (mainly making sure the object is created as I have done in the second last night, and making sure the dictionary is initiated, which I feel I have done in the third line) and I am still receiving the error. Any advice would be very much appreciated. Thank you!
class Groceries:
def __init__(self, grocery_list):
self.grocery_list = {}
def add_item(self, item):
item = input("name: ")
purchased = input(False)
self.grocery_list[item] = purchased
something = Groceries()
something.add_item()
The error I get is:
Traceback (most recent call last):
File "intermediate_python.py", line 14, in <module>
something = Groceries()
TypeError: __init__() missing 1 required positional argument: 'grocery_list'
I tried to resolve this error by removing grocery_list from the def init statement (not sure why this would work, I was just playing around) and the error was moved to the next line with:
Traceback (most recent call last):
File "intermediate_python.py", line 15, in <module>
something.add_item()
TypeError: add_item() missing 1 required positional argument: 'item'