Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function slope(x1, y1, x2, y2) that returns the slope of the line throug

ID: 3626749 • Letter: W

Question

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).

Here is 2 copies of code I have came up with so far. My professor said the output should print slope 2.0, 4.0, (all even numbers up to 18), and intercept starting with 4.0 and in even numbers, going up to 36.

I got one to read 2.0, 4.0.

def slope(x1,y1,x2,y2):
x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
m=(y2-y1)/(x2-x1)
return m

def intercept(x1,y1,x2,y2):
y=slope(x1,y1,x2,y2)*0+2
return y

s=slope (2,4,6,8)*2
z=intercept (4,6,8,10)*2
print s
print z

def slope(x1, y1, x2, y2):
    slope(5.0, 3.0, 4.0, 2.0)
    slope(1.0, 2.0, 3.0, 2.0)
    slope(1.0, 2.0, 3.0, 3.0)
    slope(2.0, 4.0, 1.0, 2.0)
    slope = (y2-y1)/(x2-x1)
    return slope

def intercept(x1, y1, x2, y2):
    intercept(1.0, 6.0, 3.0, 12.0)
    intercept(6.0, 1.0, 1.0, 6.0)
    intercept(4.0, 6.0, 12.0, 8.0)

    x = x1
    y = y1
    m = slope(x1, y1, x2, y2)
    b = y-(m*x)
    print bintercept(1.0, 6.0, 3.0, 12.0)




Explanation / Answer

def slope(x1,y1,x2,y2):
    x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
    m=(y2-y1)/(x2-x1)
    return m

def intercept(x1,y1,x2,y2):
    y=slope(x1,y1,x2,y2)*-x1;
    return y

s=slope (2,4,6,8)*2
z=intercept (4,6,8,10)*2
print s
print z

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote