Previous

Classes and Objects

5 / 5
Next

Lines are characterized by a slope $a$ and an intercept $b$. A point $(x,y)$ is on the line if $$ y=a\cdot x + b $$ If two lines have different slopes, they intersect at a unique point. For two lines $$ \begin{cases} y = a_1 \cdot x + b_1 \\ y = a_2 \cdot x + b_2 \end{cases} $$ if $a_1 \neq a_2$ then the $x$-coordinate of the point of interception is given by $$ x = \frac{b_1 - b_2} {a_2 - a_1} $$

Send

Capstone

Hint
Advanced

Create a class Line with:

  1. Constructor taking slope a and intercept b.
  2. Method __str__ returning "y = {a}*x + {b}"
  3. Method contains with parameter p returning True if point p lies on the line
  4. Method intersect with parameter l returning the point on which the line intersects with Line l
Help
Solve
Reset
Run
Submit
 

Test results

Test result #
Expected output
Your output

Your email has been verified!