Question: Example of Interval.txt USING PYTHON 3.6.1 An interval on the number line is denoted by a pair of values like so: (3. 8). Our intervals

 Example of Interval.txt USING PYTHON 3.6.1 An interval on the number

Example of Interval.txt

line is denoted by a pair of values like so: (3. 8).

USING PYTHON 3.6.1

An interval on the number line is denoted by a pair of values like so: (3. 8). Our intervals are closed. So this interval represents all numbers between 3 and 8 inclusive. The first number is always square brackets B in our program we will represent an interval by means of a tuple going to be strictly less than the second number. Normally in mathematics we represent a closed interval with and tuples in Python are represented with parentheses If we have two intervals like (7. 12) and (4,9), they overlap. We can collapse overlapping intervals into a single interval (4, 12). But the following two intervals 0, -2) and 1, 5) are non intersecting intervals and cannot be collapsed. The aim in this assignment is take a set of intervals and collapse all the overlapping intervals and print the smallest set of non-intersecting intervals in ascending order of the lower end of the interval The input data will be in a file called intervals.txt. There will be one or more lines of data in the file. Each line will have two integer numbers denoting an interval. The first number will be strictly less than the second number. Assume that the data file is correct. You will read in each pair of numbers and create a tuple out of them. You will store the tuples in a list. After you have read all the intervals and the list of tuples is complete you will sort the list. Then you will go through the list systematically and replace each pair of overlapping tuples with a single tuple. When you are done you should print out the list of non-intersecting tuples with one tuple per line. The list should be in ascending order of the lower end of the tuples. For the data file that is given with this problem statement, your output will have the following format Non-intersecting Intervals 25 -14 10 (12, 18) 22 30

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!