Write a program to compute the slope of a line between two points (x1, y1) and (x2, y2).

Slope = y2-y1/x2-x1

Code

# Python program for slope of line
def slope(x1, y1, x2, y2):
if(x2 - x1 != 0):
return (float)(y2-y1)/(x2-x1)
return None
# driver code
x1 = 4
y1 = 2
x2 = 2
y2 = 5
print("Slope is :", slope(x1, y1, x2, y2))

Output

Slope is : -1.5




Happy coding :)