← Back to Classes
Question 519
Line Between Two Points
Line Between Two Points
The Point class, with distance_to, is given. Write the whole Line class: a line is not a point, it HAS two of them, so the constructor stores start and end as Point attributes; length() returns the distance between them by calling self.start.distance_to(self.end); midpoint() returns a new Point whose x is the mean of the two x values and whose y is the mean of the two y values. Do NOT write a main block or any top-level test code; the tests construct the class. Input: two lines, the x and y of the end point, which the tests read as floats; the start is (0, 0), and the tests print the length and then the midpoint's x and y on one line.
Expected Output:
10.0 3.0 4.0
= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Classes
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.