🐍 Python for Everyone

← Back to interview questions

Chapter 21 Project 55 min build

Student Record Management System

A menu-driven mini-app built around this chapter's core tools as its organizing principle — a mock database layer (FakeConnection/FakeCursor) that implements mysql-connector-python's real interface (cursor(), execute(sql, params), fetchall(), fetchone(), commit()) closely enough to demonstrate genuine CRUD operations, parameterized-query safety, and reporting — all without a live MySQL server. No real network access or database connection happens anywhere in this file, so it runs identically for every learner, every time.

Example run

Output
=== Student Record Management System ===

1. List all students
2. Find a student by ID
3. Add a new student
4. Update a student's grade
5. Delete a student
6. Show class average
7. Show honor roll (grade >= 90)
8. Export all students as JSON
9. Show why SQL injection matters (safe demo, no execution)
10. Quit
Choose an option (1-10): 1

  [1] Ana Torres: 91
  [2] Ben Osei: 78
  [3] Chen Wu: 88

...
Choose an option (1-10): 3

New student's name: Dana Kim
New student's grade: 95
Added Dana Kim.

...
Choose an option (1-10): 6

Class average: 88.0

...
Choose an option (1-10): 10

Goodbye!
What you're building A menu loop with ten options: list all students, find one by ID, add a new student, update a grade, delete a student, show the class average, show the honor roll, export everything as JSON, see a safe (never-executed) SQL injection demonstration, or quit.
How to run Download starter.py below into an empty folder, then run python3 starter.py.

The pieces

Ideas to make it your own

Why this project matters

Every real student information system, HR platform, and customer database is, underneath its user interface, exactly this pattern: CRUD operations built on parameterized queries against a relational database. This project's mock database layer uses the genuine mysql-connector-python method names and call shapes throughout, so everything learned here — the cursor/execute/fetchall/commit rhythm, and the parameterized-query habit that closes off SQL injection — transfers directly to a real MySQL-backed application, changing only the connection details (Sub-topic 8's cloud-hosted, environment-variable-backed connect() call) rather than any of the query logic itself.

More project ideas

From Chapter 7 onward, you get a genuine choice of what to build. The Student Record Management System above is fully built out with a starter and reference solution — the four ideas below are not. Each is a real, grounded use case solvable with only what's been taught through Chapter 21. No starter or solution files are provided on purpose — building one of these unassisted is the point.

1 MongoDB-Style Document-Store Inventory Tracker (Mocked)

Problem: A small warehouse needs to track inventory items whose attributes genuinely vary by category (electronics need a warranty_years field, groceries need an expiration_date field, clothing needs a size field) — a fixed-column table would need many unused columns per item.

What it should do: Build a FakeCollection class (following this chapter's insert_one/find/update_one/delete_one pattern) storing inventory items as plain dicts with only the fields relevant to each item's own category. Menu options: add an item, search by category, update quantity with {"$set": ...}, and list everything.

Suggested approach: Reuse this project's exact CRUD-function naming convention, swapping the MySQL-style FakeCursor for a FakeCollection — the shape doesn't change based on which database style is mocked, only the underlying storage and query methods.

2 Cloud Connection-String Config Validator

Problem: Before a real deployment, a team wants a small tool that checks whether all required database configuration is actually present as environment variables, without ever connecting to a real database.

What it should do: Build a function validate_db_config(required_keys) that checks os.environ for every key in required_keys, returning a report of which are present and which are missing. Menu options: run a validation check and print a report, and simulate "fixing" a missing variable by setting it (for demonstration only).

Suggested approach: Tie this directly to Sub-topic 8 — the entire tool is a small, practical extension of "credentials should come from os.environ, not be hardcoded," turned into something a team could actually run before a deployment.

3 A Simple ORM-Lite Wrapper Exercise

Problem: Writing raw parameterized SQL for every single query gets repetitive — a very small "ORM-lite" (Object-Relational Mapper) could wrap common patterns into reusable functions.

What it should do: Build a small Table class wrapping a FakeConnection/FakeCursor pair, with methods like .all(), .find_by_id(id), .insert(**fields), .update(id, **fields), and .delete(id) — each internally building the exact same parameterized queries this chapter's project uses, just exposed through a friendlier interface.

Suggested approach: Note in your own README that real ORMs (like SQLAlchemy for Python) do exactly this at a much larger scale — generating parameterized SQL automatically from higher-level method calls.

4 Library Checkout System with Two Mock Backends

Problem: A library wants to compare a relational design (books and checkouts as separate related tables) against a document design (each book's checkout history nested inside its own document) for the exact same real-world data.

What it should do: Build the same checkout system twice: once using a MySQL-style FakeCursor with a separate checkouts table joined by book_id, and once using a FakeCollection where each book document has a nested checkout_history list. Menu options let a user check a book in/out and view its history, through either backend.

Suggested approach: This is the most direct way to build Sub-topic 7's relational-vs-document comparison yourself — write a short README section stating which backend felt simpler for which specific operation, and why.

← Interview Questions All Chapters →