Skip to content

04-16: CSV Student Report

Python: Fundamentals

View the live site — ijk37.com

Project 16

Home  |  All Projects  |  Notes  |  Exercises  |  Quiz Hub

Reads student scores from students.csv, calculates averages and letter grades, and generates a formatted report. Supports filtering by pass/fail or grade, sorting, and saving the summary to a new CSV file.

Topics covered: csv.DictReader · csv.DictWriter · csv.writer · type conversion · filtering with comprehensions · sorted(key=lambda) · pathlib.Path · functions

Difficulty: ⭐⭐ Intermediate


How to Run

python main.py

A sample students.csv is auto-created if it doesn't exist.


Sample Output

  Name            Avg   Grade   GPA  Status
  ────────────────────────────────────────────────
  Riya             95.2  A+     4.0  ✅ PASS
  Nasrin           91.8  A+     4.0  ✅ PASS
  Rahim            83.2  A-     3.7  ✅ PASS
  Karim            56.0  C      2.0  ✅ PASS
  Salma            43.0  F      0.0  ❌ FAIL

Key Concepts Practised

Concept Where used
csv.DictReader Reading rows as dicts
csv.DictWriter Writing structured output
float(row["Math"]) Type conversion from string
Comprehension + condition filter_by_grade(), filter_passing()
sorted(key=lambda s: s["average"]) Flexible sorting