## Friday, May 21, 2021

Solution Exercise 36: python algorithm which calculates the average of the scores with coefficients #### Exercise 36

Write a Python algorithm as a function which takes as parameter a couple (listScores, listCoefficients) and which returns the average obtained, where listScores designates the list of scores obtained by a students and listCoefficients designates the list of associated coefficients

#### Solution

``````def average (listScores, listCoefficients):
# initialization of the mean
average = 0
# sum of the coefficients initialized
sumCoefficients = 0

for i in range (0, len(listScores)):
# calculate the sum of the sum(coefficients*scores)
average = average + listScores [i] * listCoefficients [i]
# calculate the sum of the coefficients
sumCoefficients = sumCoefficients + listCoefficients [i]
average = average/sumCoefficients
return average

# Example
listScores = [16, 14, 12]
listCoefficients = [2, 1, 4]
print ("The average is:", average (listScores, listCoefficients))
# The output is: The average is: 13.428571428571429``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 