Q:

Why is my function changing my b-value part way through?

Once my function gets to calculating c, b = 3, which I don't understand at all. Could someone explain how I fix this?
def get_y(m, b, x):
      y = m*x + b
      return y

    #Write your calculate_all_error function here
    def calculate_all_error(m, b, x_y):
        data1, data2, data3, data4 = x_y
        a = get_y(m, b, data1[0])
        b = get_y(m, b, data2[0])
        c = get_y(m, b, data3[0])
        d = get_y(m, b, data4[0])
        return data3[0], c

    #every point in this dataset lies upon y=x, so the total error should be zero:
    datapoints = [(1, 1), (3, 3), (5, 5), (-1, -1)]
    print(calculate_all_error(1, 0, datapoints))

Output is (5,8)

A:

As already mentioned in your comments, at b = get_y(m, b, data2[0]) the value of b changed and new b which is 3 passed in codes coming after.
Just give a new name for that variable like below will make it work. now the result is (5,5)
def get_y(m, b, x):
    print(str(m),str(b),str(x))
    y = m*x + b
    return y

#Write your calculate_all_error function here
def calculate_all_error(m, b, x_y):
    data1, data2, data3, data4 = x_y
    a = get_y(m, b, data1[0])
    b1 = get_y(m, b, data2[0])
    c = get_y(m, b, data3[0])
    d = get_y(m, b, data4[0])
    return data3[0], c

#every point in this dataset lies upon y=x, so the total error should be zero:
datapoints = [(1, 1), (3, 3), (5, 5), (-1, -1)]
print(calculate_all_error(1, 0, datapoints))

