Open In App

Student management system in Python

Last Updated : 04 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Problem Statement: Write a program to build a simple Student Management System using Python which can perform the following operations:

  1. Accept
  2. Display
  3. Search
  4. Delete
  5. Update
Prerequisite: Classes and objects in python 

Approach: Below is the approach to doing the above operations:

  1. Accept – This method takes details from the user like name, roll number, and marks for two different subjects.
# Method to enter new student details
def accept(self, Name, Rollno, marks1, marks2 ):
    # Creates a new class constructor
    # and pass the details
    ob = Student(Name, Rollno, marks1, marks2 )

    # list containing objects of student class
    ls.append(ob)
  1. Display – This method displays the details of every student.
# Function to display student details     
def display(self, ob):
    print("Name   : ", ob.name)
    print("RollNo : ", ob.rollno)
    print("Marks1 : ", ob.m1)
    print("Marks2 : ", ob.m2)
    print("\n")    
  1. Search – This method searches for a particular student from the list of students. This method will ask the user for roll number and then search according to the roll number
# Search Function    
def search(self, rn):
    for i in range(ls.__len__()):
        # iterate through the list containing
        # student object and checks through
        # roll no of each object
        if(ls[i].rollno == rn):
            # returns the object with matching 
            # roll number
            return i 
  1. Delete – This method deletes the record of a particular student with a matching roll number.
# Delete Function                                  
def delete(self, rn):
    # Calls the search function 
    # created above
    i = obj.search(rn)  
    del ls[i]
  1. Update – This method updates the roll number of the student. This method will ask for the old roll number and new roll number. It will replace the old roll number with a new roll number.
# Update Function   
def update(self, rn, No):
    # calling the search function
    # of student class
    i = obj.search(rn)
    ls[i].rollno = No

Below is the implementation of the above approach: 

Python3




# This is simplest Student data management program in python
 
# Create class "Student"
class Student:
 
  # Constructor
    def __init__(self, name, rollno, m1, m2):
        self.name = name
        self.rollno = rollno
        self.m1 = m1
        self.m2 = m2
 
    # Function to create and append new student
    def accept(self, Name, Rollno, marks1, marks2):
   
  # use ' int(input()) ' method to take input from user
        ob = Student(Name, Rollno, marks1, marks2)
        ls.append(ob)
 
    # Function to display student details
    def display(self, ob):
        print("Name : ", ob.name)
        print("RollNo : ", ob.rollno)
        print("Marks1 : ", ob.m1)
        print("Marks2 : ", ob.m2)
        print("\n")
 
    # Search Function
    def search(self, rn):
        for i in range(ls.__len__()):
            if(ls[i].rollno == rn):
                return i
 
    # Delete Function
    def delete(self, rn):
        i = obj.search(rn)
        del ls[i]
 
    # Update Function
    def update(self, rn, No):
        i = obj.search(rn)
        roll = No
        ls[i].rollno = roll
 
 
# Create a list to add Students
ls = []
# an object of Student class
obj = Student('', 0, 0, 0)
 
print("\nOperations used, ")
print("\n1.Accept Student details\n2.Display Student Details\n3.Search Details of a Student\n4.Delete Details of Student\n5.Update Student Details\n6.Exit")
 
# ch = int(input("Enter choice:"))
# if(ch == 1):
obj.accept("A", 1, 100, 100)
obj.accept("B", 2, 90, 90)
obj.accept("C", 3, 80, 80)
 
# elif(ch == 2):
print("\n")
print("\nList of Students\n")
for i in range(ls.__len__()):
    obj.display(ls[i])
 
# elif(ch == 3):
print("\n Student Found, ")
s = obj.search(2)
obj.display(ls[s])
 
# elif(ch == 4):
obj.delete(2)
print(ls.__len__())
print("List after deletion")
for i in range(ls.__len__()):
    obj.display(ls[i])
 
# elif(ch == 5):
obj.update(3, 2)
print(ls.__len__())
print("List after updation")
for i in range(ls.__len__()):
    obj.display(ls[i])
 
# else:
print("Thank You !")


Output:

Operations used,

1.Accept Student details
2.Display Student Details
3.Search Details of a Student
4.Delete Details of Student
5.Update Student Details
6.Exit



List of Students

Name   :  A
RollNo :  1
Marks1 :  100
Marks2 :  100


Name   :  B
RollNo :  2
Marks1 :  90
Marks2 :  90


Name   :  C
RollNo :  3
Marks1 :  80
Marks2 :  80



 Student Found,
Name   :  B
RollNo :  2
Marks1 :  90
Marks2 :  90


2
List after deletion
Name   :  A
RollNo :  1
Marks1 :  100
Marks2 :  100


Name   :  C
RollNo :  3
Marks1 :  80
Marks2 :  80


2
List after updation
Name   :  A
RollNo :  1
Marks1 :  100
Marks2 :  100


Name   :  C
RollNo :  2
Marks1 :  80
Marks2 :  80


Thank You !


Previous Article
Next Article

Similar Reads

Python - Student’s t Distribution in Statistics
We know the mathematics behind t-distribution. However, we can also use Python to implement t-distribution on a dataset. Python provides a unique package scipy for various statical techniques and methods. We will use this package for t-distribution implementation. prerequisite: t-distribution What is t-Distribution The t-distribution, also known as
5 min read
Python program to sort and find the data in the student records
Consider a software for maintaining records of the students in a class. Consider the following functions which are required to be performed: Sorting of names according to First Name of the students.Finding the Minimum marks among all the marksFinding contact number of student using his/her First Name. The task is to write a Python program to implem
4 min read
Movie tickets Booking management system in Python
In this article, we are going to code a simple program for book movie tickets. It will be very useful to the passionate beginners who wanted to work on any project. Write a program to build a simple Movie tickets Booking Management System using Python. We had used six functions as follows : t_movie()theater()timing(a)movie(theater)center()city() Ap
5 min read
Health Management System using Python
Sometimes we are so busy that we are not even able to care for our body and by caring we mean fitness, food, exercises and much more, and then we think that we need to make our diet plan or exercise plan to maintain our body. So let's make a Python script to maintain this record for us. In this program, we add our diet and exercises that we need to
7 min read
Boutique Management System using Python-MySQL Connectivity
In this article, we are going to make a simple project on a boutique management system using Python MySql connectivity. Introduction This is a boutique management system made using MySQL connectivity with Python. It uses a MySQL database to store data in the form of tables and to maintain a proper record of all details. Different SQL queries that i
15+ min read
Python File System Quota Management
Managing file system quotas is crucial in preventing storage abuse and ensuring fair resource allocation. Python, being a versatile and powerful programming language, offers several methods to implement file system quota management. In this article, we will explore four simple yet effective methods with practical examples. Python File System Quota
3 min read
Event Management System Using Python Django
In today's fast-paced world, businesses, schools, and groups need to organize events well. An Event Management System (EMS) makes planning and managing events easier. This article will explain the structure, important parts, and how to build a helpful Event Management System with Django. Event Management System using DjangoHere, we will create the
13 min read
College Management System using Django - Python Project
In this article, we are going to build College Management System using Django and will be using dbsqlite database. In the times of covid, when education has totally become digital, there comes a need for a system that can connect teachers, students, and HOD and that was the motivation behind building this project. This project allows HOD, staff, an
15+ min read
Employee Management System using Python
The task is to create a Database-driven Employee Management System in Python that will store the information in the MySQL Database. The script will contain the following operations : Add EmployeeRemove EmployeePromote EmployeeDisplay EmployeesThe idea is that we perform different changes in our Employee Record by using different functions for examp
8 min read
Building Blog CMS (Content Management System) with Django
Django is a python based web application framework that is helpful for building a variety of web applications. Django also includes an extensible Django-Admin interface, Default SQLIte3 database, which is also extensible to PostgreSQL, MySQL databases, and a few other components to build efficient web apps. Install and Setup Django Create a directo
10 min read