
# most preferred way to write it
# has only one return
# and also doesn't continue through the list unnecessarily (that is, when an element is not div 3)
# so it is more efficient than the two functions at the end of this file
def all_divisible_by_3(alist):

    answer = True
    for item in alist:
        if item % 3 != 0:
            answer = False
            break

    return answer

# efficient, but has two returns which is not considered good programming practice
def all_divisible_by_3_c(alist):

    for item in alist:
        if item % 3 != 0:
            return False

    return True # as long as we never returned False

# inefficient (that is, if an early element is not divisible by 3, it still continues looking
# at all the rest of the numbers which is not necessary)
# also takes up more space by creating a new list
def all_divisible_by_3_a(alist):

    newlist = []
    for item in alist:
        if item % 3 == 0:
            newlist.append(item)

    if len(newlist) == len(alist):
        return True
    else:
        return False


# inefficient (that is, if an early element is not divisible by 3, it still continues looking
# at all the rest of the numbers which is not necessary)
def all_divisible_by_3_b(alist):

    numdiv3 = 0
    for item in alist:
        if item % 3 == 0:
            numdiv3 += 1

    if numdiv3 == len(alist):
        return True
    else:
        return False
