Exercise 8
Write an algorithm in python that returns the average of the terms of a list of numbers.
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def avgList(L): # initialization of the average m = 0 for x in L: m = m + x # mean = sum (of elements of L)/len(L) m = m/len(L) return m # Example L = [5, 8, 4, 3] print("the average is: m = ", avgList(L)) # the output is: the mean is: m = 5.0 |
Younes Derfoufi
CRMEF OUJDA
1 thought on “Solution Exercise 8: python algorithm which calculates the average of the elements of a list”