Basic Student Management System0%
Basic Student Management System
Beginner20 min read•Updated: 2026-09-03
Basic Student Management System
Capstone project: combine object-oriented thinking, dictionaries, loops, conditions, and file handling into a comprehensive Student Management System.
Key Concepts & Detailed Explanation
undefined
Code Examples & Output
Python
# Comprehensive Student Management System
class Student:
def __init__(self, student_id, name, course, marks):
self.student_id = student_id
self.name = name
self.course = course
self.marks = marks # dictionary of subject: marks
def average(self):
return sum(self.marks.values()) / len(self.marks)
def grade(self):
avg = self.average()
if avg >= 90: return "A+"
if avg >= 75: return "A"
if avg >= 60: return "B"
return "C"
class InstituteManager:
def __init__(self, institute_name):
self.name = institute_name
self.students = {}
def enroll_student(self, student):
self.students[student.student_id] = student
print(f"Enrolled: {student.name} (ID: {student.student_id})")
def display_leaderboard(self):
print(f"\n{'='*45}")
print(f" {self.name} - Leaderboard")
print(f"{'='*45}")
# Sort students by average score descending
ranked = sorted(self.students.values(), key=lambda s: s.average(), reverse=True)
for rank, s in enumerate(ranked, 1):
print(f"#{rank} {s.name:<18} | Avg: {s.average():>5.1f}% | Grade: {s.grade()}")
print(f"{'='*45}\n")
# Demonstration
manager = InstituteManager("MSK Institute")
manager.enroll_student(Student("MSK-101", "Aarav Sharma", "Python", {"Theory": 92, "Practical": 96}))
manager.enroll_student(Student("MSK-102", "Bhavna Patel", "Python", {"Theory": 85, "Practical": 88}))
manager.enroll_student(Student("MSK-103", "Chirag Verma", "Python", {"Theory": 94, "Practical": 98}))
manager.display_leaderboard()
Expected Output:
Output
Enrolled: Aarav Sharma (ID: MSK-101)
Enrolled: Bhavna Patel (ID: MSK-102)
Enrolled: Chirag Verma (ID: MSK-103)
=============================================
MSK Institute - Leaderboard
=============================================
#1 Chirag Verma | Avg: 96.0% | Grade: A+
#2 Aarav Sharma | Avg: 94.0% | Grade: A+
#3 Bhavna Patel | Avg: 86.5% | Grade: A
=============================================
Best Practices & Common Pitfalls
Encapsulating data and behavior inside classes (like Student and InstituteManager) keeps projects modular and maintainable.
Practice Quiz
1. What design paradigm is used when binding data and methods together inside a class?
- A) Object-Oriented Programming (OOP)
- B) Pure Functional Programming
- C) Assembly
- D) Procedural Only
Answer: A
Explanation: Classes and objects embody Object-Oriented Programming (Encapsulation).
2. How are students sorted by their average grade descending?
- A) sorted(students, key=lambda s: s.average(), reverse=True)
- B) students.sort_average()
- C) students.order()
- D) reverse(students)
Answer: A
Explanation: The sorted() function with a lambda key extracts the metric to sort on.
Practice Challenge
Add a method 'save_to_file(filename)' that persists all student records to disk and 'load_from_file(filename)' that reloads them.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Expense Tracker | None |
Practice Quiz
Test your understanding of this lesson with 1 questions. Each question has one correct answer.