def create_sloping_step_function(start_x, start_y, end_x, end_y):
    """
    create sloping step function, returning start y-value for input values below starting x-value, ending y-value
        for input values above ending x-value and connecting slope through the middle

    :param start_x: float
        starting x-value
    :param start_y: float
        starting y-value
    :param end_x: float
        ending x-value
    :param end_y: float
        ending y-value
    :return: function
        sloping function as described above
    """
    gradient = (end_y - start_y) / (end_x - start_x)

    def step_function(age):
        if age < start_x:
            return start_y
        elif start_x <= age < end_x:
            return gradient * age + start_y - gradient * start_x
        elif end_x <= age:
            return end_y

    return step_function