Loading lessons...
Project 9: CSV Grade Report
Project 9: CSV Grade Report
Read student data from a CSV file and print a report of who passed and who failed.
The goal
Given a CSV file of names and scores, read it, decide pass (60+) or fail, and write a summary.
What you practice
- File reading with open()
- String split()
- Conditionals
- File writing
Sample data file (grades.csv)
Ada,88
Bob,42
Cam,71
Starter code
with open("grades.csv") as f:
for line in f:
line = line.strip()
name, score = line.split(",")
print(name, score)
Step-by-step
- Run the starter and confirm each line reads.
- Convert the score with int().
- Print "PASS" or "FAIL" next to each student.
- Count how many passed and failed.
- Write the report to a file with open(..., "w").
- Wrap everything in a try/except for a missing file.
Checklist
- [ ] The file opens and reads
- [ ] Each line splits into name and score
- [ ] The score converts to int
- [ ] Pass/fail logic works
- [ ] The report writes to a file
- [ ] A missing file is handled
TL;DR
- open() + a for loop reads a file line by line.
- split(",") separates CSV columns.
- with closes the file automatically.