Calculate distance and slope of a line in Python