Managing student records is a frequent requirement in educational institutions. Today, we'll design a basic Student Management System using Python, one of the most versatile languages available. This beginner-friendly tutorial will guide you through creating a system with essential CRUD operations (Create, Read, Update, and Delete).
Objective
To develop a simple Python program that allows the user to:
- Add a student's details
- Display all students
- Update student details
- Delete a student
Implementation
Let's start by defining our student data model.
class Student:
def __init__(self, roll_no, name, marks):
self.roll_no = roll_no
self.name = name
self.marks = marks
This simple Student class will help us encapsulate and manage student data.
Storage For the sake of simplicity, we'll use a list to store our student data:
students = []
CRUD Operations
Create:
def add_student():
roll_no = int(input("Enter roll number: "))
name = input("Enter name: ")
marks = float(input("Enter marks: "))
student = Student(roll_no, name, marks)
students.append(student)
print(f"Student {name} added successfully!")
Read:
def display_students():
for student in students:
print(f"Roll No: {student.roll_no}, Name: {student.name}, Marks: {student.marks}")
Update:
def update_student():
roll_no = int(input("Enter the roll number of the student to update: "))
for student in students:
if student.roll_no == roll_no:
student.name = input("Enter new name: ")
student.marks = float(input("Enter new marks: "))
print("Student details updated!")
break
else:
print("Student not found!")
Delete:
def delete_student():
roll_no = int(input("Enter the roll number of the student to delete: "))
for index, student in enumerate(students):
if student.roll_no == roll_no:
del students[index]
print(f"Student with roll number {roll_no} deleted!")
break
else:
print("Student not found!")
User Interaction:
We will use a simple loop to allow user interaction:
def main():
while True:
choice = input("""
1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: """)
if choice == '1':
add_student()
elif choice == '2':
display_students()
elif choice == '3':
update_student()
elif choice == '4':
delete_student()
elif choice == '5':
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
Code Explanation
We began by defining a Student class to represent student data.
The four functions (add_student, display_students, update_student, delete_student) implement our CRUD operations.
The main() function drives our application, presenting a menu to the user and responding to their choices.
Complete Source Code of Student Management System with Output
class Student:
def __init__(self, roll_no, name, marks):
self.roll_no = roll_no
self.name = name
self.marks = marks
students = []
def add_student():
roll_no = int(input("Enter roll number: "))
name = input("Enter name: ")
marks = float(input("Enter marks: "))
student = Student(roll_no, name, marks)
students.append(student)
print(f"Student {name} added successfully!")
def display_students():
for student in students:
print(f"Roll No: {student.roll_no}, Name: {student.name}, Marks: {student.marks}")
def update_student():
roll_no = int(input("Enter the roll number of the student to update: "))
for student in students:
if student.roll_no == roll_no:
student.name = input("Enter new name: ")
student.marks = float(input("Enter new marks: "))
print("Student details updated!")
break
else:
print("Student not found!")
def delete_student():
roll_no = int(input("Enter the roll number of the student to delete: "))
for index, student in enumerate(students):
if student.roll_no == roll_no:
del students[index]
print(f"Student with roll number {roll_no} deleted!")
break
else:
print("Student not found!")
def main():
while True:
choice = input(""" 1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: """)
if choice == '1':
add_student()
elif choice == '2':
display_students()
elif choice == '3':
update_student()
elif choice == '4':
delete_student()
elif choice == '5':
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
Output:
1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: 1
Enter roll number: 100
Enter name: Ramesh
Enter marks: 90
Student Ramesh added successfully!
1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: 2
Roll No: 100, Name: Ramesh, Marks: 90.0
1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: 3
Enter the roll number of the student to update: 100
Enter new name: Ram
Enter new marks: 70
Student details updated!
1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: 2
Roll No: 100, Name: Ram, Marks: 70.0
1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: 4
Enter the roll number of the student to delete: 4
Student not found!
1. Add student
2. Display students
3. Update student
4. Delete student
5. Exit
Enter your choice: 5
Conclusion
This Python-based Student Management System offers a fundamental introduction to CRUD operations. It's simple and extensible. If you're up for a challenge, consider enhancing it by adding data validation, storing student data in a file, or incorporating more advanced features! Happy coding!
Related Posts
Mini Projects
Related Python Source Code Examples:
Python string literals
Python string length example
Python String join() method example
Python string split() method example
Python String index() method example
Python string find() method example
Python string startswith() method example
Python string endswith() method example
Python String lower() method example
Python String upper() method example
Python string title() method example
Python string capitalize() method example
Python string islower() method example
Python string istitle() method example
Python string isupper() method example
Python string swapcase() method example
Python string strip() method example
Python string replace() method example
Python string isdigit() method example
Python string isdecimal() method example
Python string isnumeric() method example
Python string isalpha() method example
Python string isalnum() method example
Write a python program to concatenate strings in different ways
Python program to create a new string by appending s2 in the middle of s1
Split a given string on asterisk into several substrings and display each substring in Python
Write a Python program to count all lower case, upper case, digits, and special symbols from a given string
Write a python program to return a string such that the string is arranged from lowercase letters and then uppercase letters
Write a Python Class to Reverse a String Word by Word
Write a python class to implement pow(x, n)
Write a python class to convert an integer to a Roman numeral
Write a python program to find the factorial of a number using recursion
Write a Python program to convert temperature in Celsius to Fahrenheit
Write a Python program to find the largest number among the three input numbers
Write a Python program to print only even numbers using the function
Write a python program to filter integer, float, string from a list
Write a python program to check whether the given number is greater than 50 and also divisible by 2 using nested if else
Write a python program to demonstrate a simple class creation
Write a python program to demonstrate the object as an argument
Write a python program to demonstrate an object as an argument with default values
Write a python program to demonstrate method overriding
Write a Python program for Linear Search and Binary Search
Python list - insert, remove, append, len, pop and clear example
Write a python program to add two numbers
Write a python program to get the python version
Write a python program to check whether the first and last letters of the given word is vowel or not ?
Write a python program to count the number of digits
Write a python program to filter integer, float, string from a list
Write a python program to find the average of 10 numbers
Write a python program to traverse a list and print the values in it
Write a python program to print first 20 natural numbers using while loop
Write a python program to print the square of all numbers from 1 to 10
Write a python program to get the sum of digits
Write a python program to print right angle triangle pattern using *
Write a python program to remove vowels in a word
Write a python program to find absolute value using function
Wrtie a python program to demonstrate the use of variable length arguments
Write a python program to demonstrate the use of default arguments
Write a python program to demonstrate the use of keyword arguments
Write a python program to print a simple list using functions
Write a python program to find the max values in a list using function
Given a string of odd length greater 7, return a string made of the middle three chars of a given String
Arrange string characters such that lowercase letters should come first
Write a Python program to Count all lower case, upper case, digits, and special symbols from a given string
Write a Python program to Find all occurrences in a given string ignoring the case
Given an input string, count occurrences of all characters within a string and return the details as dictionary
Write a Python program to Split a given string on asterisk into several substrings and display each substring
Write a Python program to Check whether the given string startswith 'h'
Write a python program to concatenate strings in different ways
Write a python program to return a string such that the string is arranged from lowercase letters and then uppercase letters
Write a python program to repeat a givent string multiple times
Write a python program to create a simple list and nested list with different datatypes
Write a python program to add elements to an existing list from user input
Write a python program to reverse a given list
Write a python program to convert a list to tuple using tuple function
Write a python program to check whether the user given input is equal to the current working directory or not
Write a Python program for Linear Search and Binary Search
Selection Sort Algorithm in Python
Bubble Sort Algorithm in Python
Bogo Sort Algorithm in Python
Bucket Sort Algorithm in Python
Comb Sort Algorithm in Python
Counting Sort Algorithm in Python
Heap Sort Algorithm in Python
Insertion Sort Algorithm in Python
Merge Sort Algorithm in Python
Quick Sort Algorithm in Python
Shell Sort Algorithm in Python
Interpolation Search Algorithm in Python
Stack Implementation in Python
Queue Implementation in Python
Deque Implementation in Python
Singly Linked List Implementation in Python
Doubly Linked List Implementation in Python
Circular Linked List Implementation in Python
PriorityQueue Implementation in Python
Circular Queue Implementation in Python
Binary Search Tree Implementation in Python
Stack Implementation Using Linked List in Python
Stack Implementation Using Doubly Linked List in Python
Python - Convert Binary to Decimal Example
Python - Convert Binary to Hexadecimal Example
Python - Convert Binary to Octal Example
Python - Convert Decimal to Binary Example
Python - Convert Decimal to Octal Example
Python Convert String to Int
Python Convert String to DateTime
Python Convert String to Date
Python Convert String to JSON
Python Convert String to Number
Python Convert String to List
Python Convert String to Float
Python Convert String to Bytes
Python Convert List to String
Python Convert List to Set
Python Convert List to Dictionary
Python Convert List to Tuple
Python Convert List to JSON
Python Convert List to Array
Python Convert List to String With Commas
Python Convert List to Dataframe
Python Convert Set to List
Python Convert Set to String
Python Convert Set to Tuple
Python Convert Set to Dictionary
Python Convert Set to JSON
Python Convert Set to Comma Separated String
Python Convert Dictionary to JSON
Python Convert Dictionary to Dataframe
Python Convert Dictionary to String
Python Convert Dictionary to List
Python Convert Dictionary Keys to List
Python Convert Dictionary Values to List
Python Convert Dictionary to Tuple
Python Convert Array to String
Python Convert Array to String With Commas
Python Convert Array to List
Python Convert Array to Set
Python Convert Array to JSON
Python Convert Array to Dictionary
Python Convert Array to Tuple
Python Convert Int to String
Python Convert Int to Binary
Python Convert Int to Float
Python Convert Date to String
Python Convert Date to Epoch
Python Convert Date to Unix Timestamp
Python Convert Date to DateTime
Python Convert Date to DateTime
Python Convert Date to Timestamp
Python Convert Date String to DateTime
Python Convert Date String to Epoch
Python Convert Tuple to String
Python Convert Tuple to List
Python Convert Tuple to Dictionary
Python Convert Tuple to Comma Separated String
Python Convert Tuple to Array
Python Convert Tuple to JSON
Python Convert JSON to String
Python Convert JSON to Dictionary
Python Convert JSON to Array
Python Convert JSON to XML
Python Convert JSON to List
Python
Comments
Post a Comment