I was given the task to write a function that will search for the maximum average score of students, I got to the point where the code outputs the average score of each student. but I don’t know how to find the maximum. I tried to put it in the “list”, but it didn’t work
students = [
{"name": "John", "surname": "Doe", "grades": [5, 5, 4, 4]},
{"name": "Jane", "surname": "Doe", "grades": [4, 3, 4, 3, 5]},
{"name": "Bill", "surname": "Gates", "grades": [5, 5, 5, 3]},
{"name": "Steve", "surname": "Jobs", "grades": [3, 5, 4, 3, 3, 5]},
{"name": "Guido", "surname": "Van Rossum", "grades": [5, 3, 5, 4, 5, 5, 3, 5]},
{"name": "Elon", "surname": "Musk", "grades": None}
]
for i in students:
if i['grades'] == None:
print('this is zero')
else:
len_list = len(i['grades'])
sum_list = sum(i['grades'])
average_list = (round(sum_list / len_list,1))
my_list = []
my_list.append(average_list)
print(average_list)
Outputs just 6 numbers, each of which is in a separate “list”.
New contributor
feizerti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.