Question: 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

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.

append, 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.

odds() – write a method odds() which returns an intlist consisting of the odd int’s. They should not be removed from the original.

evens() – 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):

append

insert

The constructor – when passed a list that contains something other an int

Step by Step Solution

3.45 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the intlist class lets first ensure the class is a subclass of Pythons builtin list This enables us to override and customize its functio... View full answer

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

Document Format (2 attachments)

PDF file Icon

609715b70d8ca_27478.pdf

180 KBs PDF File

Word file Icon

609715b70d8ca_27478.docx

120 KBs Word File

Students Have Also Explored These Related Programming Questions!