Task: Write a function that takes in a list of numbers and outputs the mean of the numbers using the formula for mean. Do this without any built-in functions like sum(), len(), and, of course, mean()


In [37]:
def mean_function(num_list):
    number_of_elements = 0
    sum_of_numbers = 0
    for number in num_list:
        number_of_elements = number_of_elements + 1
        sum_of_numbers = sum_of_numbers + number
        mean_of_numbers = sum_of_numbers/number_of_elements
    return mean_of_numbers

In [43]:
numbers_list=[1,2,3,4,5]
mean_function(numbers_list)


Out[43]:
3.0