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 |
|---|---|
| 10 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB