Sue and Kathy were doing their algebra homework. They were asked to write the equation of the line that

passes through the points (–3, 4) and (6, 10). Sue wrote y - 4 = 2/3(x + 3) and kathy wrote y = 2/3x + 6. Write a recursive function to represent this same relationship.

1 answer

def find_slope(p1, p2):
return (p2[1] - p1[1]) / (p2[0] - p1[0])

def find_intercept(slope, point):
return point[1] - slope * point[0]

def equation_of_line(point1, point2):
slope = find_slope(point1, point2)
intercept = find_intercept(slope, point1)

def line_eq(x):
return slope * x + intercept

return line_eq

line_function = equation_of_line((-3, 4), (6, 10))

print(line_function(0)) # Prints the value of y when x = 0 for the line passing through (-3, 4) and (6, 10)