Exercise 78
Given a list made up of the students' averages avg_list, write a python algorithm that determines the first index of the average which is less than 10. Example if
avg_list = [12, 17, 10, 7, 11, 14, 15, 9]
, the algorithm returns index 3.
Solution
def avgInf10 (L):
# initialization of the index of average which is less than 10
avg_index = 0
for i in range (0, len (L)):
if L[i] < 10:
avg_index = i
break
return avg_index
# Example
avg_list = [12, 17, 10, 7, 11, 14, 15, 9]
print (avgInf10 (avg_list))
#The output of the program is: 3
Younes Derfoufi
my-courses.net
my-courses.net