def avg(tup):
    """
    Returns average of all of the elements in the tuple.

    Remember that the average of a tuple is the sum of all of the elements in the
    tuple divided by the number of elements in the tuple.

    Examples:
        avg((1.0, 2.0, 3.0)) returns 2.0
        avg((1.0, 1.0, 3.0, 5.0)) returns 2.5

    Parameter tup: the tuple to check
    Precondition: tup is a tuple of numbers (int or float)
    """
    assert type(tup) == tuple

    result = 0.0

    for index in tup:
        if len(tup) == 0:
            return result
        elif len(tup) == 1:
            result = float(tup[0])
        elif len(tup) > 1:
            result = sum(tup[:]) / float(len(tup))
        else:
            result = 'nil'

    return result
    # pass