PYTHON Write a class Locker that represents a collection of items. You must writ
ID: 3881040 • Letter: P
Question
PYTHON
Write a class Locker that represents a collection of items. You must write the entire class yourself. A template is not included in the .py file, you must create the Locker class and Iterator yourself. The class supports six methods
1. 25 Points: Write a class Locker that represents a collection of items. You must write the entire class yourself. A template is not included in the py file, you must create the Locker class and Iterator yourself. The class supports six methods a init which takes an optional parameter representing the maximum amount of items that can be stored in the locker. It sets the maximum size of the collection to the provided value or to the value 10 if no number is given as a parameter. It also creates an empty list to store the items in the collection but does not allow passing a list via the constructor as a parameter bcontains 0 which takes an item as a parameter and returns True if the item is alreadv in the collection and False otherwise. The function must return a Boolean and not a string. Note: The in operator uses contains c. addO which adds a new item to the Locker. It does this by first checking that the maximum capacity for the collection hasn't been reached. If the maximum capacity has been reached, then the method returns False without modifying the collection. If the maximum capacity has not yet been reached, the method checks that the item is not already in the collection using the_ contains method described above. If the item is already there, the method returns False and does not modify the collection. If the item is not present and the maximum capacity has not yet been reached, the method adds the item to the collection and returns True The function must return a Boolean and not a string d. size0 which returns the number of items currently in the collection. e str O which returns a string representing the obiect as seen in the sample output below g iter_0 which returns an iterator for the class. The iterator should move from the mostly recently added item to the item first added to the Locker. See the sample output below for examples. Please note that whatever classes you need for this question should be included in the file you submit. You should not reference any files other than the csc242hw4.py fileExplanation / Answer
Locker class is defined with all the 6 methods and their implementations done. As __str__() and __itr__() sample example details are not given in the question, I tried to implement them as per the question specifications.
CODE TO COPY
--------------------------------------------------------------------------------------------------------------------------------
If you have any doubts about the answer, please let me know in the comments so that I can help
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.