import math


def p75(lis, exception=0.0, cycles=False):
    """Calculates the average of the upper half of a list.

    lis is the list that is averaged.
    exception is returned if there is a divide by zero error. The
    default is 0.0 because the main usage in in percentage calculations.
    cycles is whether or not the data set is cycle times. If it is, it
    takes the bottom half of the list, rather than the upper half,
    because the lower half is the faster cycle times.
    """
    # Removes the Nones from the list because if they are part of the
    # list, it returns an error.
    lis = [item for item in lis if item is not None]
    if len(lis) == 0:
        return exception
    else:
        # If the cycles specifcation is true, it takes the lower half of
        # the list, which are the faster cycle times.
        if cycles is True:
            # 'math.ceil()' rounds the float up to be an int.
            upper_half = lis[:math.ceil(len(lis) / 2)]
        else:
            # 'math.floor()' rounds the float down to be an int.
            upper_half = lis[-math.floor(len(lis) / 2):]
        return sum(upper_half) / len(upper_half)