def median(x):
    """
    Median of X.

    :param list or tuple x: array to calculate median.
    :return: median.
    :rtype: int or float
    :raise ValueError: when len of x == 0.
    """
    if x:
        sorted_x = sorted(x)
        n = len(x)
        mid = n // 2
        if n % 2 == 1:
            return sorted_x[mid]
        else:
            return (sorted_x[mid] + sorted_x[mid-1]) / 2

    else:
        raise ValueError('len of x == 0')