So I have a dictionary
alice = { "name": "Alice", "homework": [100.0, 92.0, 98.0, 100.0], "quizzes": [82.0, 83.0, 91.0], "tests": [89.0, 97.0] }
and a function that takes the average of a list
def average(numbers):
return float(sum(numbers))/len(numbers)
The problem is here. I want python, with the function get_average(), to read through a dictionary. After that I want the function to take the average of a list in the dictionary and multiply the average of that list with a specific number (grading weights with .10 for homeworks,.30 for quizzes,or.60 for test) and give the total of the weighted homeworks, quizzes, and test. I am using a if statement to check whether the list selected from the for-loop in the dictionary is homework, quizzes, or tests.
def get_average(alice):
hw=0
qz=0
ts=0
for assignment in student:
if assignment== ["homework"]:
hw=average(assignment)*.10
if assignment==["quizzes"]:
qz=average(assignment)*.30
if assignment==["tests"]:
ts=average(assignment)*.60
return hw+qz+tsenter code here
This only returns zero. It should be 91.15
Aucun commentaire:
Enregistrer un commentaire