#620 · File handling · Advanced · 130 XP · about 25 min
The CSV file source has the header name,subject,mark and then one row per mark, in no particular order, so each student has several rows. Write make_report(source, target) that writes a new CSV file target with the header name,subjects,average,best and then one row per student:
subjects: how many marks the student has.average: their average mark, rounded to one decimal place with round(..., 1), so it is written like 81.7 or 80.0.best: the subject of their highest mark. If several subjects share it, the one that comes first in alphabetical order.Put the students with the highest average first. Students with the same average go in alphabetical order of their names. Use the csv module for reading and writing, and replace whatever target held before.
Return the name of the student at the top of the report, or '' if source has no marks.
If marks.csv holds:
name,subject,mark Asha,Math,90 Ben,Math,70 Asha,English,72 Ben,Science,88 Asha,Science,90 Cara,Math,80
then make_report('marks.csv', 'report.csv') returns 'Asha' and report.csv holds:
name,subjects,average,best Asha,3,84.0,Math Cara,1,80.0,Math Ben,2,79.0,Science
Asha's 90 in Math and 90 in Science tie, and Math comes first in alphabetical order.
source has at most 10,000 rows and no blank lines.First solves only, ranked by stars and then time.