Question: Needed in Python 3 please. 2. Implement a class intlist which a list that stores only integers. You MUST subclass list. Please note the following:

Needed in Python 3 please.

Needed in Python 3 please. 2. Implement a class intlist which a

list that stores only integers. You MUST subclass list. Please note the

following: *constructor- can be passed a list of ints, or, by default

2. Implement a class intlist which a list that stores only integers. You MUST subclass list. Please note the following: *constructor- can be passed a list of ints, or, by default constructs an empty intlist appena, insert, extend -can also be used to add ints to an intlist. If you don't know how extend works for a list, look it up. All should raise errors if a non-int is added. .setitem-can be used for item assignment using an index. Raises error if non-int is used. *dds (-wre a method odds () which returns an intlist consisting of the odd int's. They should not be removed from the original. evens O-same as odds , but for even ints NotIntError-also write an Exception class NotIntError that subclasses Exception. NotIntError- a NonIntError should be raised when client code attempts to place something other than an int in an intlist. This can happen in three ways (all shown in code below): o append o insert o The constructor-when passed a list that contains something other an in Note: you can check whether item is an int by evaluating the expression type(item)-int o Your goal is to get the following behavior: >>> intlist) >>> il-intlist([1,2, 3]) intlist([1, 2, 3]) >>> 11 . append ( 5 ) intlist ([1, 2, 3, 5]) >>> il.insert (1,99) >>> intlist ([1, 99, 2, 3, 5]) >>>il extend (22,44,66] intlist ([1, 99, 2, 3, 5, 22, 44, 6 >>> odds - .oads() >>odds intlist([1, 99, 3, 5]) >>> evensns ) >>evens intlist ([2, 22, 44, 66]) >>> intlist ([1, 99, 2, 3, 5, 22, 44, 66]) >>> [2]--12 # calls seti ten intlist ([1, 99,-12, 3, 5, 22, 44, 66]) >>> [4] # calls setitem. Trying to put anything except for an int into an intlist will always raise an NotIntError. Note that there 5 different ways this could be attempted: >iappend (33.4)11 Traceback (most recent call last): NotIntError: 33.4 not an int >>> il.insert (2, True) Traceback (most recent call last): NotIntError: True not an int >>> il-intlist ([2,3, 4, "apple"]) Traceback (most recent call last): NotIntError: apple not an int >>> il extend [2,3, 'hello']) Traceback (most recent call last): NotIntErxor: hello not an int Traceback (most recent call last): : 22.3 not an int

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!