You will write three functions for lines: a test for collinear points, the line through two points, and the intercepts of a line. The checker tests them on many cases, including vertical lines.
The idea. Points , , are collinear when the slopes of and match. Cross-multiplying avoids a division by zero. A line is with , and its intercepts are and .
Your tasks.
collinear(a, b, c). Return True or False, using cross-multiplication and no division.line_through(p, q): return the pair (m, c), or None for a vertical line.intercepts(m, c): return (x_intercept, y_intercept). The -intercept is None when m is .Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…