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.
1. Project Overview
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
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 YourselfOutput:
# 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 YourselfOutput:
=== Testing Data Layer ===
5. Design Highlights
▶ Example: Student Data Operations (Difficulty ⭐)
▶ Try it YourselfOutput:
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
- Uniform function return: Each function returns a
(bool, str)tuple —Truemeans success,Falsemeans failure, and the string is the message. - Encapsulated repeated operations: The
load_data()andsave_data()functions are reused across all data operations. - Input validation: Score range checking and student ID existence checks are done in the data layer, so upper-layer callers don't need to repeat them.
- Ready for expansion: Lessons 35 and 36 will add functionality on top of this data layer.
❓ FAQ
os.path.join() to construct paths and avoid hardcoding.(success, message) tuple instead of raising exceptions?success, which is lighter than try/except. It's suitable for small CLI tools; for larger projects, custom exception classes are recommended.📖 Summary
- The project uses a three-layer architecture: Data Layer -> Logic Layer -> Presentation Layer; this lesson completes the data layer
- Data is persisted in JSON format; student IDs serve as dictionary keys for O(1) lookup
- Scores range from 0 to 100, validated on entry
- All operation functions return
(success, message)tuples for easy caller handling
📝 Exercises
-
Beginner (Difficulty: Star): Run the data layer code above, add 2-3 students with their grades, and verify the JSON file is generated correctly.
-
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). -
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).