def median(y):
    """
    Return the median (middle value) of numeric y.

    When the number of y points is odd, return the middle y point.
    When the number of y points is even, the median is interpolated by
    taking the average of the two middle values:

    >>> median([1, 3, 5])
    3
    >>> median([1, 3, 5, 7])
    4.0
    """
    y = sorted(y)
    n = len(y)
    if n%2 == 1:
        return y[n//2]
    else:
        i = n//2
        return (y[i - 1] + y[i])/2