I am working on a function to find the slope of a line if given x1, y1 and x2, y2. Not too hard. But I need the results to be floating point not integers even though the x and y inputs are integers. I have :

def slope(x1, y1, x2, y2):
        >>> slope(5, 3, 4, 2)
        >>> slope(1, 2, 3, 2)
        >>> slope(1, 2, 3, 3)
        >>> slope(2, 4, 1, 2)
    y = y2 - y1
    x = x2 - x1
    m = y / x
    return m

The comment inside the definition is what I am really working on (testing functions), but not my problem right now. It fails the test because it expects 1.0 as the first answer and as an integer gets 1. I tried making m into float(m), but get an error that I can't call a function right there. How do I turn a variable into a floating decimal number?

That was the trick! Thanks to all of you guys for helping with such elementary questions.

This question has already been answered. Start a new discussion instead.