Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Define a data type Interval in interval. py that represents a closed ID interval. The data type must support the following API: $ python interval.
Define a data type Interval in interval. py that represents a closed ID interval. The data type must support the following API: $ python interval. py 3.14 0 1 0.5 1 2 1.5 2.5 2.5 3.5 3 4 [2.5, 3.5] contains 3. 140000 [3.0, 4.0] contains 3.140000 [0.0, 1.0] intersects [0.5, 1.5] [0.0, 1.0] intersects [1.0, 2.0] [0.5, 1.5] intersects [1.5, 2.5] [1.0, 2.0] intersects [1.5, 2.5] [1.5, 2.5] intersects [2.5, 3.6] [2.6, 3.6] intersects [3.0, 4.0] import stdio import sys class Interval; Represents a 1-dimensional interval [lbound, rbound]. def _init _(self, lbound, rbound): self- ___ lbound = self ___ rbound = def lbound (self): Returns the lower bound of the interval. def rbound (self): Returns the upper bound of the interval. Def contains (self, x): Returns True if self contains the point x and False otherwise def intersects (self, other): Returns True if self intersects other and False otherwise. Def ___ str ___ (self): Returns a string representation of self. # Test client [DO NOT EDIT]. Reads a float x from the command Line and # writes to standard output: all of the intervals from standard input # (each defined by a pair of floats) that contain x; and all pairs # of intervals from standard input that intersect one another def ___main(): x - float (sys.argv[1]) intervals = [] While not stdio.isEmpty(): lbound - stdio. readFloat () rbound - stdio.readFloat () intervals += [Interval(lbound, rbound)] for i in range (len (intervals)): if intervals[i]. contains(x): studio.writef('ss contains , intervals[i], x) for I in range (len(intervals)); for j in range (i + 1, Len (intervals)): if intervals[i]. intervals)): if intervals[i]. intersects(intervals[j]): stdio. writef ('%s, intersects '%s ', intervals[i], intervals[j] if ___name___-- ' ___main___': _main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started