Here's the question you clicked on:
cyberdemon93
As an exercise, write a function slope(x1, y1, x2, y2) that returns the slope of the line through the points (x1, y1) and (x2, y2). Then use this function in a function called intercept(x1, y1, x2, y2) that returns the y-intercept of the line through the points (x1, y1) and (x2, y2). I have done the first part but i keep getting confused when i reach the second part.
from the first part make equation now for y intercept put x==0 in equation u will gwt intercepts
If you consider the generic equation of a line : y = ax + b when you get the slope, you actually get the 'a' of your equation. You also have an x and an y (you can take for exemple x1 and y1). All you need to do is to infer the value of b, which is precisely the y-intercept asked.
the equation of a line is \[y=mx+b\], where m is the slope of the line, and b is the offset from the origin along the y axis. The y-intercept is the value of y where x = 0, so\[y = 0m + b\]\[y = b\] For any point that you know exists on the line, you can solve for b. \[y_1 = mx_1 + b\]\[b = y_1 - mx_1\]So all intercept(x1,y1,x2,y2) has to do is return y1 - slope(x1,y1,x2,y2) * x1