Question: python2.7 1. 25 Points: Write a class Bag that represents a collection of items. You must write the entire class yourself. A template is not

python2.7
 python2.7 1. 25 Points: Write a class Bag 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 Bag

1. 25 Points: Write a class Bag 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 Bag class and Iterator yourself. The class supports six methods Bag Class: a init 0 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 b contains_0 which takes an item as a parameter and returns True if the item is already in the collection and False otherwise. The function must return a Boolean and not a string. Note: The in operator uses contains c. add) 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. size) which returns the number of items currently in the collection e str0which returns a string representing the object 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 Bag. 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 file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!