Student Management System Using Python

sruti_ganakan June 03, 2026

A Student Management System is a simple application that helps store and manage student records. Using Python, we can create a menu-driven program that allows users to add student details, search for records, calculate percentages, and store data permanently through file handling.

Features

The application provides the following features. - Add a Student. - Search for a student by Roll number. - Calculate the total marks and percentage of a student using their roll number. - Save records in a file. - Reload records when the program starts.

Module File (student_function.py)

This file contains all the functions used in the project.

students = []

def add_students():
    """
    Adds a new student record by taking roll number,
    name, and marks as input. The record is stored
    in a list and saved to a file.
    """
    roll = int(input("Enter your roll number: "))
    name = input("Enter your name: ")

    maths = int(input("Enter marks obtained in maths: "))
    phy = int(input("Enter marks obtained in physics: "))
    chem = int(input("Enter marks obtained in chemistry: "))

    student_info = {
        "Roll no: ": roll,
        "Name: ": name,
        "Marks: ": {
            "Maths: ": maths,
            "Physics: ": phy,
            "Chemistry: ": chem
        }
    }
    print("")

    for student in students:
        if student["Roll no: "] == roll:
            print("Roll number already exist.")
            return

    students.append(student_info)

    file = open("student.txt", "a")
    file.write(str(student_info) + "\n")
    file.close()

    print("\nStudent added successfully.\n")
    print(student_info, "\n")


def reload_student():
    """
    Loads previously saved student records from
    the file and stores them in the students list.
    """

    file = open("student.txt", "r")

    for line in file:

        student_info = eval(line.strip())
        students.append(student_info)

    file.close()


def display_stud():
    """
    Searches for a student using the roll number
    and displays the student's details and marks.
    """
    roll_no = int(input("Enter roll number of the student: "))
    print("")

    for student_info in students:

        if student_info["Roll no: "] == roll_no:

            print("Roll no: ", student_info["Roll no: "])
            print("Name: ", student_info["Name: "])

            print("")
            print("Marks in: ")

            print("Maths: ", student_info["Marks: "]["Maths: "])
            print("Physics: ", student_info["Marks: "]["Physics: "])
            print("Chemistry: ", student_info["Marks: "]["Chemistry: "])

            print("")
            return

    print("Roll number not found.\n")


def student_result():
    """
    Calculates and displays the total marks and
    percentage of a student using the roll number.
    """
    roll_no = int(input("Enter the roll number of the student: "))
    print("")

    for student_info in students:

        if student_info["Roll no: "] == roll_no:

            total = student_info["Marks: "]["Maths: "]
            total = total + student_info["Marks: "]["Physics: "]
            total = total + student_info["Marks: "]["Chemistry: "]

            percentage = (total / 300) * 100

            print("Total marks:", total)
            print("Percentage:", percentage)

            print("")
            return

    print("Student not found.")

Functions included

  • add_student()
  • reload_student()
  • display_stud()
  • student_result()

These functions handle student registration, searching, result calculation, and file reloading.

Main Program (student_management.py)

This file imports the module and provides the menu-driven interface.

import student_function

try:
    file = open("student.txt", "r")
    file.close()

    student_function.reload_student()

except FileNotFoundError:
    file = open("student.txt", "w")
    file.close()

while True:

    print("1. Add Student")
    print("2. Search Student by Roll Number")
    print("3. Calculate Percentage of a Student")
    print("4. Exit\n")

    choice = int(input("Enter your choice: "))
    print("")

    if choice == 1:

        student_function.add_students()

    elif choice == 2:

        student_function.display_stud()

    elif choice == 3:

        student_function.student_result()

    elif choice == 4:

        print("Exiting.")
        break

    else:

        print("Invalid choice.")
  1. Add student
  2. Search student by roll number
  3. Calculate the percentage of a student
  4. Exit

The program loads previously saved records using reload_student() and continues running until the user chooses to exit.

How the Program works

  1. The user enters student details.
  2. Records are stored using dictionaries and lists.
  3. Data is saved in student.txt.
  4. Saved records are reloaded whenever the program starts.
  5. Students can be searched using their roll number.
  6. The system calculates the total marks and percentage of a student using their roll number.
0 Likes
17 Views

Filters

No filters available for this view.

Reset All