Trying to get a program to fine the slope and intercept of a line on a graph....
I've got it all working so far...except the last line. I broke it down into pieces and ran it assigning numbers to the variables, but in the program, it doesn't work. Here is the code...

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

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

It keeps giving me this error

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    intercept(12, 20, 24, 40)
  File "C:\Users\Tony\Documents\Module 2 SLP\slope", line 11, in intercept
    b = y - m*x
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

If I'm understanding this correctly, it's telling me the * is an unsupported operand...but I thought * was an operator?
I tried

b = y - (m*x)

and that didn't work either....any hints?

Your function 'slope' should return the value of 'm' when it finishes.

def slope(x1, y1, x2, y2):
    a = (float(y2 - y1))
    b = (float(x2 - x1))
    m = float(a / b)
    return m
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.