Question: Using Python object oriented programming, write a class called Interval that represents a one-dimensional open interval on the real line. This main purpose of this
Using Python object oriented programming, write a class called Interval that represents a one-dimensional open interval on the real line. This main purpose of this class is to simplify overlapping continuous intervals. The code below should get you started but there are a lot of missing pieces that will have to figure out The API should take a pair of integers as input and respond to the operator such that >>> a = Interval(1,3) >>> b - Interval(2,4) >>> C Interval(5,10) >> a + b Interval(1,4) >>> b+c Interval(2,4), Interval(5,10) . Note that in the case of non-overlapping intervals, the output should be a list of constituent Intervals. Keep in mind that these are open interval Specifically, >>> Interval(2,3)+Interval (1,2) Interval(2,3), Interval(1,2) . Note that these do not produce a single interval because each interval is open (not closed). The interval endpoints can be negative also (c.9.. Interval(-10,-3) is valid). The output does not have to be sorted. It's up to you to write the dunder functions for your object. If you do this right, you will have a very general solution to this problem This is where good object-oriented design pays off. Noto: Make sure to implement_cq_method below, to pass all the test cases in the grader. Starter Code: u out the necessary methods shown below and aod others if need be. class Intervallobject) definit__(self, a,b): 101 Integer ib: Integer essert ab assert is instanceta, int) assert is instancet,ant) sell. self._bb der repr__(self): pas det-ee_(selt, other Dass dettisetf.other) pass det-st__(self other pass der gesett other) DASS det celt, others pass det_10_{self other) DASS
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
