#1

``````Replace this line with your code.
lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}

def average(numbers):

total = sum(numbers)
total = float(total)
total = total / len(numbers)

def get_average(student):
student["homework"] = average(student["homework"])
student["quizzes"] = average(student["quizzes"])
student["tests"] = average(student["tests"])
return (student["homework"] * 10 + student["quizzes"] * 30 + student["tests"]*60) / 100

if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"

def get_class_average(students):
results = []

for each in students:

results.append(get_average(each))
return average(results)``````

what is the problem I cant understand!!!

#2

a function ends the moment a return keyword is reached

so your function ends in the first iteration/run of the loop, so your function won't calculate the correct class average for a class of two or more students

#3

yes I see that but I did it for 'each' of them ,so I have to write a code for each one of them in order to have the correct answer or not?

best regards

#4

return will end the function, so the function must end in the first iteration of the loop because of return (loop will break)

so you will need to place return outside the loop so the whole loop can

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.