def percentile(sorted_values, p):
size = len(sorted_values)<EOL>idx = (p / <NUM_LIT>) * size - <NUM_LIT:0.5><EOL>if idx < <NUM_LIT:0> or idx > size:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(size, p))<EOL><DEDENT>return sorted_values[int(idx)]<EOL>
Calculate the percentile using the nearest rank method.

    >>> percentile([15, 20, 35, 40, 50], 50)
    35

    >>> percentile([15, 20, 35, 40, 50], 40)
    20

    >>> percentile([], 90)
    Traceback (most recent call last):
        ...
    ValueError: Too few data points (0) for 90th percentile