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
Step: 1
class intlistlist l def initself li selfl li def setitemself key val ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Document Format ( 2 attachments)
609715b70d8ca_27478.pdf
180 KBs PDF File
609715b70d8ca_27478.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started