grades = [
# First line is descriptive header. Subsequent lines hold data
['Student', 'Exam 1', 'Exam 2', 'Exam 3'],
['Ken', '100', '90', '80'],
['Pat', '88', '99', '111'],
['Sam', '45', '56', '67'],
['Jon', '59', '61', '67']
]
Question:
Complete the function build_grade_dicts, again taking grades as a parameter and returning new dictionary, grade_dicts,
that maps names of students to dictionaries containing their scores. Each entry of this scores dictionary should be keyed on assignment name
and hold the corresponding grade as an integer. For instance, grade_dicts['Ken']['Exam 1'] == 100.
My Solution so far:
CODE:
def build_grade_dicts(grades):
###
### YOUR CODE HERE
###
grade_dicts = dict()
for L in grades[1:]:
grade_dicts[L[0]] = dict(zip(assignments, [int(g)
for g in L[1:]]))
return grade_dicts
print(build_grade_dicts(grades))
My Output:
{'Ken': {'Exam 1': 100, 'Exam 2': 90, 'Exam 3': 80}}
What I should be getting:
{'Ken': {'Exam 1': 100, 'Exam 2': 90, 'Exam 3': 80},
'Pat': {'Exam 1': 88, 'Exam 2': 99, 'Exam 3': 111},
'Sam': {'Exam 1': 45, 'Exam 2': 56, 'Exam 3': 67},
'Jon': {'Exam 1': 59, 'Exam 2': 61, 'Exam 3': 67}}
Please help, thank you.
Unlock access to this and over
10,000 step-by-step explanations
Have an account? Log In