Python Programming Input Format In the code template below, you are given two classes: Point, which represents a point in 2D space, and The first line contains an integer n, the number of lines to follow. Line, which represents a set of collinear points. The next n lines contain the 2D coordinate values of each point, with the following format: To get the distance between two points, we just use the Euclidean distance formula for 2D: Constraints For simplicity, assume that all x and y values in Point objects are integers. d = /(x2 – 21)² + (y2 – Y1)² Assume that there would be no inputs that would result to lines with an infinite slope. Assume that the input number n will always be greater than 2. The slope of a line given two points (x1.y1) and (x2.y2), is given by this formula: Output Format Y2 - Y1 We can override the str_ method in the Point class such that it returns the 2D coordinates in the format: (x,y). m = We can override the str method in the Line class such that it returns a string containing all the collinear points in the line. To check if a point (x1.y1) lies in a line with slope m, we can just use the slope-intercept form given by: Sample Input 0 y - Y1 = m( - 2) 3 The first two Point objects in the points attribute of a Line instance would dictate its slope and intercept. Afterward, an instance of your Line class should be able to add collinear points to points. 0,0 1,1 3,-3 Sample Output 0 You cannot remove the first two points in the points attribute of a Line instance. This is to retain its slope and intercept. Your tasks are: Instatiating a Line: [(0, 0), (1, 1)] Adding More Points: [(0, 0), (1, 1)] Adding Redundant Points: [(0, 0), (1, 1)] Trying to Remove Last Input Point: [(0, 0), (1, 1)] Trying to Remove All Points: [(0, 0), (1, 1)] 1. To complete the other methods in the Point and Line classes. 2. To create instances of the Point class and create an instance of the Line class whose points contain are instances of the Point class that are collinear with each other.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

will give thumbs up!

Python problem (see pic) 

Template: 

### Template

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        """ Returns a string showing the coordinates with the format (x,y) """
        # -- YOUR CODE HERE --

    def __eq__(self, other):
        """ Checks if two points pertain to the same coordinates """
        # -- YOUR CODE HERE --
        

    def get_distance(self, other):
        """ Calculates the distance between two points """
        # -- YOUR CODE HERE --

class Line:
    def __init__(self, point_a, point_b):
        self.points = [point_a, point_b]

    def __str__(self):
        """ Returns a string containing all collinear points in the Line instance """
        # -- YOUR CODE HERE --

    def get_slope_intercept(self):
        """ Calculates the slope of the line """
        # -- YOUR CODE HERE --
    
    def add_points(self, points):
        """ Adds a list of collinear points to the Line instance """
        # -- YOUR CODE HERE --          

    def remove_points(self, points):
        """ Removes a list of points from the Line instance """
        # -- YOUR CODE HERE --

if __name__ == "__main__":
    list_points = []
    n = int(input())
    for x in range(n):
        input_line = input().split(',')
        # -- YOUR CODE HERE

    # Instantiate a Line using the first two input points
    myLine = 

    # If your methods are defined correctly, the following lines should produce the desired output in the test cases.
    print("Instatiating a Line: ")
    print(myLine)
    myLine.add_points(list_points[2:-1])
    print("Adding More Points: ")
    print(myLine)    
    myLine.add_points(list_points)
    print("Adding Redundant Points: ")
    print(myLine)    
    print("Trying to Remove Last Input Point:")
    myLine.remove_points([list_points[-1]])
    print(myLine)
    print("Trying to Remove All Points:")
    myLine.remove_points(list_points)
    print(myLine)

Python Programming
Input Format
In the code template below, you are given two classes: Point, which represents a point in 2D space, and
Line, which represents a set of collinear points.
The first line contains an integer n, the number of lines to follow.
The next n lines contain the 2D coordinate values of each point, with the following format:
<x>,<y>
To get the distance between two points, we just use the Euclidean distance formula for 2D:
Constraints
For simplicity, assume that all x and y values in Point objects are integers.
d =
V(22 - 21) + (y2 – Y1)?
Assume that there would be no inputs that would result to lines with an infinite slope.
Assume that the input number n will always be greater than 2.
The slope of a line given two points (x1,y1) and (x2.y2), is given by this formula:
Output Format
We can override the str method in the Point class such that it returns the 2D coordinates in the
Y2- Y1
format: (x,y).
m =
x2 - 21
We can override the str method in the Line class such that it returns a string containing all the
collinear points in the line.
To check if a point (x1.y1) lies in a line with slope m, we can just use the slope-intercept form given by:
Sample Input 0
y – Y1 = m(x – r1)
3
0,0
1,1
The first two Point objects in the points attribute of a Line instance would dictate its slope and intercept.
Afterward, an instance of your Line class should be able to add collinear points to points.
3,-3
Sample Output 0
You cannot remove the first two points in the points attribute of a Line instance. This is to retain its slope
and intercept.
Instatiating a Line:
[(0, 0), (1, 1)]
Adding More Points:
[ (о, 0), (1, 1)]
Adding Redundant Points:
[ (о, 0), (1, 1)]
Trying to Remove Last Input Point:
[(0, 0), (1, 1)]
Trying to Remove All Points:
[(0, 0), (1, 1)]
Your tasks are:
1. To complete the other methods in the Point and Line classes.
2. To create instances of the Point class and create an instance of the Line class whose points contain are
instances of the Point class that are collinear with each other.
Transcribed Image Text:Python Programming Input Format In the code template below, you are given two classes: Point, which represents a point in 2D space, and Line, which represents a set of collinear points. The first line contains an integer n, the number of lines to follow. The next n lines contain the 2D coordinate values of each point, with the following format: <x>,<y> To get the distance between two points, we just use the Euclidean distance formula for 2D: Constraints For simplicity, assume that all x and y values in Point objects are integers. d = V(22 - 21) + (y2 – Y1)? Assume that there would be no inputs that would result to lines with an infinite slope. Assume that the input number n will always be greater than 2. The slope of a line given two points (x1,y1) and (x2.y2), is given by this formula: Output Format We can override the str method in the Point class such that it returns the 2D coordinates in the Y2- Y1 format: (x,y). m = x2 - 21 We can override the str method in the Line class such that it returns a string containing all the collinear points in the line. To check if a point (x1.y1) lies in a line with slope m, we can just use the slope-intercept form given by: Sample Input 0 y – Y1 = m(x – r1) 3 0,0 1,1 The first two Point objects in the points attribute of a Line instance would dictate its slope and intercept. Afterward, an instance of your Line class should be able to add collinear points to points. 3,-3 Sample Output 0 You cannot remove the first two points in the points attribute of a Line instance. This is to retain its slope and intercept. Instatiating a Line: [(0, 0), (1, 1)] Adding More Points: [ (о, 0), (1, 1)] Adding Redundant Points: [ (о, 0), (1, 1)] Trying to Remove Last Input Point: [(0, 0), (1, 1)] Trying to Remove All Points: [(0, 0), (1, 1)] Your tasks are: 1. To complete the other methods in the Point and Line classes. 2. To create instances of the Point class and create an instance of the Line class whose points contain are instances of the Point class that are collinear with each other.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY