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
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
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
609715b70d8ca_27478.pdf
180 KBs PDF File
609715b70d8ca_27478.docx
120 KBs Word File
