Python Student Management System

In the last lesson, Python Expense Tracker, we built a project that saves and summarizes expense data. Now we will build a student management system for working with student records.

In this tutorial, we will build a Python Student Management System from scratch using VS Code. This is a practical beginner project that teaches JSON file handling, dictionaries, lists, loops, functions, searching, updating, and deleting records. By the end, we will have a working system that can add, view, search, update, and delete student records, all saved to a file.

What Is a Student Management System?

A Student Management System is a program that helps us keep track of student information. We can add new students with their name, age, and grade. Then we can view all students, search for a specific student, update their details, and delete records we no longer need.

Think of it like a digital record book. Instead of writing on paper, we type student details into the program. And the program remembers them for us.

Student Management Systems are used in schools, colleges, and coaching centers. They are simple but very useful.

Features of Our Python Student Management System

Our system will have these features:

  • Add a student with name, age, and grade
  • View all students in a table
  • Search for a student by name
  • Update student information
  • Delete a student
  • Save records to a JSON file
  • Load records when the program starts

Project Folder Structure

We will create a folder for our project. Inside it, we will have one Python file and one JSON file.

student_system/
students.py
students.json

The students.json file stores our student records. It will be created automatically when we save our first record.

Let us set up the project in VS Code.

Setting Up the Project in VS Code

Step 1: Open VS Code

If we do not have VS Code installed, we can download it from code.visualstudio.com. It is free.

Once installed, open VS Code.

Step 2: Create a New Folder

  • Click on File in the top menu.
  • Click Open Folder.
  • Navigate to where we want to keep our project (like Desktop or Documents).
  • Click New Folder.
  • Name it student_system.
  • Click Select Folder.

Now VS Code is open with our new empty folder.

Step 3: Create the Python File

  • In the left sidebar, we see our folder name student_system.
  • Right-click on the folder name.
  • Click New File.
  • Name it students.py.
  • Press Enter.

Now we have an empty students.py file ready for code.

Step 4: Open the Integrated Terminal

  • Click on Terminal in the top menu.
  • Click New Terminal.

A terminal panel opens at the bottom. It is already inside our student_system folder. So we do not need to cd anywhere.

Now we are ready to write code.

How to Create the Student Management System in Python (Step by Step)

We will write the code in small steps. Before each step, we will explain what we are doing and why. We will mention which file we are editing (always students.py in this project).

Step 1: Import Required Modules

We need two modules. json for saving and loading student records, and os for checking if the file exists.

students.py
import json
import os

Step 2: Define the Students File

We will store student records in a file called students.json. Let us define it as a constant.

students.py
STUDENTS_FILE = "students.json"

Step 3: Create a Function to Load Students

When the program starts, we want to show the user their existing records. So we read the file and convert it back into a Python list of dictionaries.

students.py
def load_students():
if not os.path.exists(STUDENTS_FILE):
return []
with open(STUDENTS_FILE, "r") as file:
return json.load(file)

Step 4: Create a Function to Save Students

Whenever we add, update, or delete a student, we save the changes so they are not lost.

students.py
def save_students(students):
with open(STUDENTS_FILE, "w") as file:
json.dump(students, file, indent=4)

Step 5: Create a Function to Add a Student

The user types the student’s name, age, and grade. We add it to our list and save the updated list to the file.

students.py
def add_student(students):
name = input("Enter student name: ").strip()
if not name:
print("Name cannot be empty")
return
try:
age = int(input("Enter age: "))
grade = float(input("Enter grade: "))
except ValueError:
print("Please enter valid numbers")
return
student = {
"name": name,
"age": age,
"grade": grade
}
students.append(student)
save_students(students)
print(f"Student added: {name}")

Step 6: Create a Function to View All Students

The user needs to see all student records. We loop through the list and print each student in a formatted table.

students.py
def view_students(students):
if not students:
print("No students yet")
return
print("\nAll Students:")
print("-" * 50)
print(f"{'Name':<20} {'Age':>5} {'Grade':>8}")
print("-" * 50)
for s in students:
print(f"{s['name']:<20} {s['age']:>5} {s['grade']:>8.2f}")
print("-" * 50)

Step 7: Create a Function to Search for a Student

The user can search for a student by name. We do a partial match, so typing “al” will find “Alex”.

students.py
def search_student(students):
name = input("Enter student name to search: ").strip().lower()
found = [s for s in students if name in s["name"].lower()]
if not found:
print("No student found")
return
print("\nSearch Results:")
for s in found:
print(f"Name: {s['name']}, Age: {s['age']}, Grade: {s['grade']}")

Step 8: Create a Function to Update a Student

The user can update a student’s age or grade. We find the student by name and update the fields.

students.py
def update_student(students):
name = input("Enter student name to update: ").strip()
for s in students:
if s["name"].lower() == name.lower():
print(f"Current info: Name={s['name']}, Age={s['age']}, Grade={s['grade']}")
new_age = input("Enter new age (leave blank to keep): ").strip()
new_grade = input("Enter new grade (leave blank to keep): ").strip()
if new_age:
try:
s["age"] = int(new_age)
except ValueError:
print("Invalid age")
if new_grade:
try:
s["grade"] = float(new_grade)
except ValueError:
print("Invalid grade")
save_students(students)
print("Student updated")
return
print("Student not found")

Step 9: Create a Function to Delete a Student

The user can delete a student record by name.

students.py
def delete_student(students):
name = input("Enter student name to delete: ").strip()
for i, s in enumerate(students):
if s["name"].lower() == name.lower():
removed = students.pop(i)
save_students(students)
print(f"Deleted: {removed['name']}")
return
print("Student not found")

Step 10: Create the Main Menu Function

This is the control center. It shows the options to the user and calls the right function based on their choice.

students.py
def main():
students = load_students()
while True:
print("\n===== STUDENT MANAGEMENT =====")
print("1. Add student")
print("2. View all students")
print("3. Search student")
print("4. Update student")
print("5. Delete student")
print("6. Exit")
choice = input("Enter your choice: ").strip()
if choice == "1":
add_student(students)
elif choice == "2":
view_students(students)
elif choice == "3":
search_student(students)
elif choice == "4":
update_student(students)
elif choice == "5":
delete_student(students)
elif choice == "6":
print("Goodbye!")
break
else:
print("Invalid choice")

Step 11: Run the Student Management System Program

Finally, let us add the program entry point.

students.py
if __name__ == "__main__":
main()

Complete Python Student Management System Code

Now our complete students.py file looks like this.

import json
import os
STUDENTS_FILE = "students.json"
def load_students():
if not os.path.exists(STUDENTS_FILE):
return []
with open(STUDENTS_FILE, "r") as file:
return json.load(file)
def save_students(students):
with open(STUDENTS_FILE, "w") as file:
json.dump(students, file, indent=4)
def add_student(students):
name = input("Enter student name: ").strip()
if not name:
print("Name cannot be empty")
return
try:
age = int(input("Enter age: "))
grade = float(input("Enter grade: "))
except ValueError:
print("Please enter valid numbers")
return
student = {
"name": name,
"age": age,
"grade": grade
}
students.append(student)
save_students(students)
print(f"Student added: {name}")
def view_students(students):
if not students:
print("No students yet")
return
print("\nAll Students:")
print("-" * 50)
print(f"{'Name':<20} {'Age':>5} {'Grade':>8}")
print("-" * 50)
for s in students:
print(f"{s['name']:<20} {s['age']:>5} {s['grade']:>8.2f}")
print("-" * 50)
def search_student(students):
name = input("Enter student name to search: ").strip().lower()
found = [s for s in students if name in s["name"].lower()]
if not found:
print("No student found")
return
print("\nSearch Results:")
for s in found:
print(f"Name: {s['name']}, Age: {s['age']}, Grade: {s['grade']}")
def update_student(students):
name = input("Enter student name to update: ").strip()
for s in students:
if s["name"].lower() == name.lower():
print(f"Current info: Name={s['name']}, Age={s['age']}, Grade={s['grade']}")
new_age = input("Enter new age (leave blank to keep): ").strip()
new_grade = input("Enter new grade (leave blank to keep): ").strip()
if new_age:
try:
s["age"] = int(new_age)
except ValueError:
print("Invalid age")
if new_grade:
try:
s["grade"] = float(new_grade)
except ValueError:
print("Invalid grade")
save_students(students)
print("Student updated")
return
print("Student not found")
def delete_student(students):
name = input("Enter student name to delete: ").strip()
for i, s in enumerate(students):
if s["name"].lower() == name.lower():
removed = students.pop(i)
save_students(students)
print(f"Deleted: {removed['name']}")
return
print("Student not found")
def main():
students = load_students()
while True:
print("\n===== STUDENT MANAGEMENT =====")
print("1. Add student")
print("2. View all students")
print("3. Search student")
print("4. Update student")
print("5. Delete student")
print("6. Exit")
choice = input("Enter your choice: ").strip()
if choice == "1":
add_student(students)
elif choice == "2":
view_students(students)
elif choice == "3":
search_student(students)
elif choice == "4":
update_student(students)
elif choice == "5":
delete_student(students)
elif choice == "6":
print("Goodbye!")
break
else:
print("Invalid choice")
if __name__ == "__main__":
main()

How to Run the Student Management System in VS Code

We have two ways to run the program.

Way 1: Using the Terminal

In the VS Code terminal, type:

Terminal window
python students.py

Way 2: Using the Run Button

  • Open students.py in the editor.
  • Look at the top right corner. There is a small play button (triangle).
  • Click it. VS Code will run the file in the terminal.

Both ways work. Use whichever we prefer.

Example Output

===== STUDENT MANAGEMENT =====
1. Add student
2. View all students
3. Search student
4. Update student
5. Delete student
6. Exit
Enter your choice: 1
Enter student name: Alex
Enter age: 20
Enter grade: 85.5
Student added: Alex
===== STUDENT MANAGEMENT =====
...
Enter your choice: 2
All Students:
--------------------------------------------------
Name Age Grade
--------------------------------------------------
Alex 20 85.50
--------------------------------------------------

That is our Student Management System. It is simple but complete. And we built it entirely in VS Code.

Exercises for Practice

Try these exercises to improve the Student Management System.

  1. Add a student ID field that is unique for each student.
  2. Add a course field to track which course each student is enrolled in.
  3. Add a search by grade range feature (e.g., show students with grade between 80 and 90).
  4. Add sorting options: by name, by age, or by grade.
  5. Add attendance tracking for each student.
  6. Add export to CSV for use in Excel.
  7. Add a summary that shows total students, average grade, highest grade, and lowest grade.

Now let us build the next project: the Password Generator. We will also use VS Code for that.

Next, we will build a Python Password Generator that creates strong random passwords.