Point and LineSegment

You are required to develop a Point class with two attributes: x and y, representing the x-coordinate and y-coordinate of a point on a 2D plane. The Point class should have a method named distance_from_origin that calculates and returns the distance from the point to the origin (0,0).
Subsequently, create a LineSegment class with two private attributes: p1 and p2, each being an instance of the Point class, representing the endpoints of the line segment. The LineSegment class should have a method named length that calculates and returns the length of the line segment.
Input
Output
first = Point(3, 4); second = Point(6, 8); seg = LineSegment(first, second); print(second.distance_from_origin()); print(seg.length())
10 5
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue