Student Management System in Python With Free Code


Introduction

A Student Management System (SMS) is an essential tool for educational institutions, making it easier to manage student information, including admission details, attendance, grades, and other records. Whether you’re a college administrator, teacher, or student, keeping track of numerous students manually can be a daunting task. That’s where technology, specifically a Python-based solution, can help.

Best Python Projects :- Click Here

Student Management System in Python With Source Code

Features

Before diving into the code, let’s explore some essential features of a Student Management System:

  • Adding Student Details: Input student information like name, age, student ID, and class.
  • Updating Student Information: Modify existing student records when needed.
  • Deleting Student Records: Remove students who have graduated or left the institution.
  • Displaying All Student Records: View the entire list of students in a neatly formatted manner.
  • Searching for a Specific Student: Quickly find a student by ID or name.

Getting Started

  1. Install Python: Download and install the latest version of Python from python.org.
  2. Set up an IDE: I recommend using PyCharm or VS Code. These tools offer helpful features like syntax highlighting and debugging.
  3. Install SQLite: If you’re using SQLite, make sure it’s installed on your system. Alternatively, Python’s sqlite3 library can manage the database directly.
See also  Simple Library Menu in Java with Source Code

Step-by-Step Guide to Building

Student-Management-3-1024x576 Student Management System in Python With  Free Code
Student Management System in Python Free Source Code

1. Creating the Project Structure

Start by creating a new Python project. The structure should include:

  • student_management.py: The main Python script.
  • students.db: A SQLite database to store records.

2. Designing the User Interface

You have two options: build a simple GUI with Tkinter or keep things minimalist with a console-based interface.

For a basic text-based interface, you’ll use Python’s input() and print() functions to interact with users.

3. Coding the Main Functionalities (CRUD)

CRUD stands for Create, Read, Update, Delete — the four basic functions of data management.

4. Connecting the Database

We’ll use Python’s sqlite3 module to connect and interact with the SQLite database.

import sqlite3

# Create a connection to the database
conn = sqlite3.connect('students.db')
c = conn.cursor()

# Create table
c.execute('''CREATE TABLE IF NOT EXISTS students 
             (id INTEGER PRIMARY KEY, name TEXT, age INTEGER, grade TEXT)''')

conn.commit()
conn.close()

Adding Student Details

def add_student(name, age, grade):
    conn = sqlite3.connect('students.db')
    c = conn.cursor()
    c.execute("INSERT INTO students (name, age, grade) VALUES (?, ?, ?)", (name, age, grade))
    conn.commit()
    conn.close()

name = input("Enter student name: ")
age = int(input("Enter student age: "))
grade = input("Enter student grade: ")

add_student(name, age, grade)

Displaying All Student Records

def view_students():
    conn = sqlite3.connect('students.db')
    c = conn.cursor()
    c.execute("SELECT * FROM students")
    rows = c.fetchall()

    for row in rows:
        print(f"ID: {row[0]}, Name: {row[1]}, Age: {row[2]}, Grade: {row[3]}")

    conn.close()

view_students()

Searching for a Student

def search_student(student_id):
    conn = sqlite3.connect('students.db')
    c = conn.cursor()
    c.execute("SELECT * FROM students WHERE id=?", (student_id,))
    student = c.fetchone()

    if student:
        print(f"ID: {student[0]}, Name: {student[1]}, Age: {student[2]}, Grade: {student[3]}")
    else:
        print("Student not found")

    conn.close()

student_id = int(input("Enter student ID to search: "))
search_student(student_id)

Updating Student Information

def update_student(student_id, name, age, grade):
    conn = sqlite3.connect('students.db')
    c = conn.cursor()
    c.execute("UPDATE students SET name=?, age=?, grade=? WHERE id=?", (name, age, grade, student_id))
    conn.commit()
    conn.close()

student_id = int(input("Enter student ID to update: "))
name = input("Enter new name: ")
age = int(input("Enter new age: "))
grade = input("Enter new grade: ")

update_student(student_id, name, age, grade)

Deleting a Student Record

def delete_student(student_id):
    conn = sqlite3.connect('students.db')
    c = conn.cursor()
    c.execute("DELETE FROM students WHERE id=?", (student_id,))
    conn.commit()
    conn.close()

student_id = int(input("Enter student ID to delete: "))
delete_student(student_id)
Student Management System in Python Free Source Code
See also  E-Commerce Website Using Django Framework with Free Code

student management system in python
code for student management system in python
student attendance management system in python
what is student management system
student management system examples
python student management system
student management system using python
student management system project in python

Post Comment