#150EasyFiles & Modules· The csv Module
CSV Grade Report
Input format
`csv_text`: CSV content with a `name,score` header and at least one student. Scores are whole numbers from 0 to 100.
Output format
A dictionary with keys `students`, `average`, `top` and `failed`.
Examples
Input: csv_text = "name,score\n\"Lovelace, Ada\",91\n\"Hopper, Grace\",88\n\"Babbage, Charles\",42\n"
Output: {"students":3,"average":"73.7","top":"Lovelace, Ada","failed":["Babbage, Charles"]}
The average is 221 / 3 = 73.666..., shown as 73.7. Only Babbage scored below 50.
Input: csv_text = "name,score\nSolo,50"
Output: {"students":1,"average":"50.0","top":"Solo","failed":[]}
50 is not below 50, and the file does not need to end with a newline.
Constraints
- 1 <= students <= 10^4
Study first
- #python
- #csv
- #files
- #standard-library
