9. How is Everybody Doing?

#1

current output:
83.8666666667
A
None

Oops, try again. Did you remember to print the letter grade for the class's average?

return average score and grade for 3 students

``````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 /= len(numbers)

def get_average(student):
homework = average(student["homework"]) * 0.10
quizzes = average(student["quizzes"]) * 0.30
tests = average(student["tests"]) * 0.60
return homework + quizzes + tests

score = int(score)
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 student in students:
results.append(get_average(student))
return average(results)

students = [lloyd ,alice ,tyler]

print get_class_average([lloyd, alice, tyler])
print get_letter_grade(get_average(lloyd) + get_average(alice) + get_average(tyler))``````

#2

it is easier to use the get_class_average for get_letter_grade, but you don't have to.

if you want to do it your way, don't forget to take the average of `get_average(lloyd) + get_average(alice) + get_average(tyler)`

#3

Thanks for the help. Went with your suggestion and it worked. Definitely the easier option.

#4

yea, that is why you wrote the get_class_average function in the first place, otherwise you have to implement what you tried every time you want to call the get_letter_score function for multiply students.

#5

Why can't we just use students in get_class_average?

#6

Pretty sure you can.

#7

You can, in fact, it would be better to use `students`

#8

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