Lesson 98 +55 XP

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

  1. Run the starter and confirm each line reads.
  2. Convert the score with int().
  3. Print "PASS" or "FAIL" next to each student.
  4. Count how many passed and failed.
  5. Write the report to a file with open(..., "w").
  6. 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.