Python: Project: Grade Mgmt (Pt.1)

Last updated: 2026-11-12

This is the capstone project of the Python tutorial. Over three lessons, we will build a complete student grade management system from scratch. The project has three layers: data layer (JSON persistence), logic layer (grade processing), and presentation layer (command-line interface). This lesson builds the foundation — requirements and the data layer.


Related Keywords / Statements:False True

1. Project Overview

TEXT
Student Grade Management System
├── Lesson 34: Data Layer — Requirements analysis + JSON/CSV persistence
├── Lesson 35: Logic Layer — Grade statistics + Sorting + Exception handling
└── Lesson 36: Presentation Layer — Menu interface + Search + Reports


2. Requirements Specification

TEXT
1. Student Management
   ├── Add student (name, student ID, class)
   └── Delete student (by student ID)

2. Grade Management
   ├── Enter grades (by student ID for multiple subjects)
   ├── Modify grades
   └── Delete grade records

3. Statistics and Analysis
   ├── Individual report card
   ├── Class ranking
   ├── Subject averages
   └── Score distribution

4. Data Persistence
   ├── Store data in JSON format to a file
   └── Auto-load on startup


3. Data Structure Design

▶ Example: JSON Data Structure

▶ Try it Yourself

Output:

TEXT
# Executed successfully

Tip: Why use student ID as the key? Using student ID (string) as the dictionary key makes lookups O(1) — whether there are 10 or 10,000 students, the lookup speed is the same.



4. Data Layer Implementation

▶ Example: Data Layer Implementation and Testing

▶ Try it Yourself

Output:

TEXT
=== Testing Data Layer ===


5. Design Highlights

▶ Example: Student Data Operations (Difficulty ⭐)

▶ Try it Yourself

Output:

TEXT
Added: Alice (001)
Added: Bob (002)
Entered Alice's Chinese: 85
Entered Alice's Math: 92
Entered Bob's Chinese: 78

Alice's average: 88.5
Bob's Chinese score: 78
Total students: 2


5. Design Highlights


Related Keywords / Statements:False True

❓ FAQ

Q Why use student ID as the dictionary key instead of name?
A Names can duplicate (students with the same name), but student IDs are unique identifiers. Dictionary keys must be unique; using student IDs guarantees O(1) lookup speed and no conflicts.
Q Is it good practice to hardcode the JSON file path?
A For simplicity, the tutorial hardcodes the path. In real projects, use configuration files or command-line arguments to specify the path. Use os.path.join() to construct paths and avoid hardcoding.
Q Why return a (success, message) tuple instead of raising exceptions?
A This is the "status code pattern" — the caller can decide what to do based on success, which is lighter than try/except. It's suitable for small CLI tools; for larger projects, custom exception classes are recommended.

📖 Summary


📝 Exercises

  1. Beginner (Difficulty: Star): Run the data layer code above, add 2-3 students with their grades, and verify the JSON file is generated correctly.

  2. Intermediate (Difficulty: Star-Star): Add an update_student(student_id, name=None, class_name=None) function to the data layer that only updates the provided fields (leaving others unchanged).

  3. Advanced (Difficulty: Star-Star-Star): Add batch entry functionality to add_score — accept a dictionary like {"Chinese": 85, "Math": 92} to enter multiple grades at once. Requirement: if any score is invalid, roll back the entire batch operation (don't save any data).

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏