Code Example: test_slope.py

#!/usr/bin/python3
# ===================================================================
# test slope calculation
# ===================================================================

# ---- list of line segments
# ---- each line segment is point0, point1
# ---- each point is X coord, Y coord

tests = [
        [(1,0),(5,2)],[(5,2),(1,0)],
        [(-5,-3),(-1,-1)],[(-1,-1),(-5,-3)], 
        [(-4,0),(0,2)],[(0,2),(-4,0)],
        [(0,-2),(4,0)],[(4,0),(0,-2)],

        ]

# ---- test each line segment orentation
# ---- point 0 -> point 1

i = 0
for seg in tests:

    i +=1

    print(f'------------------- test {i} --------')

    p0 = seg[0]            # line segmant point 0
    p1 = seg[1]            # line segment point 1

    print(f'p0 = {p0}')
    print(f'p1 = {p1}')

    dx = p0[0] - p1[0]
    dy = p0[1] - p1[1]

    print(f'dx = {dx}')
    print(f'dy = {dy}')

    m = dy/dx

    print(f'slope = {m}')