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.
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)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps