QuestionQ9

VerifiedWorking with Data and Performing Simple Analyses

You have a list of test scores in which every entry contains a student name and a score. Some students occur more than once. You want to calculate each student's average score and save the results in a dictionary. Here is the partial code block:

Question Image

Which code correctly replaces the # MISSING CODE comment to calculate each student's average score? Select the best answer.

Explanation

Accumulating each score into a per-student total and incrementing a per-student count for every record provides the values needed for totals[name] / counts[name]. Using dict.get(name, 0) safely supplies zero for a student not yet present while preserving the existing total and count for repeated students.

Community Discussion

No comments yet. Be the first to start the discussion!