Creating a simple Student Management System in Python is an excellent way to learn basic Python syntax and get familiar with common programming concepts like functions, lists, and dictionaries. This system will allow you to perform operations such as accepting new student details, displaying all students, searching, deleting, and updating student records.
Step 1: Setup Your Environment
Make sure Python is installed on your computer. You can download it from python.org and install it. You'll also need a text editor or an IDE (like PyCharm, Visual Studio Code, or even a simple Notepad) to write your Python script.
Step 2: Define the Data Structure
Before coding, decide how you'll store student data. A dictionary is suitable because it allows you to associate unique student IDs with their information.
students = {}
Step 3: Implement the Function to Add a New Student
def accept_student():
student_id = input("Enter student ID: ")
name = input("Enter student name: ")
age = input("Enter student age: ")
students[student_id] = {"Name": name, "Age": age}
print("Student added successfully.")
Step 4: Implement the Display Function
def display_students():
for student_id, info in students.items():
print(f"ID: {student_id}, Name: {info['Name']}, Age: {info['Age']}")
Step 5: Implement the Search Function
def search_student():
student_id = input("Enter student ID to search: ")
if student_id in students:
print(f"Found: ID: {student_id}, Name: {students[student_id]['Name']}, Age: {students[student_id]['Age']}")
else:
print("Student not found.")
Step 6: Implement the Delete Function
def delete_student():
student_id = input("Enter student ID to delete: ")
if student_id in students:
del students[student_id]
print("Student deleted successfully.")
else:
print("Student not found.")
Step 7: Implement the Update Function
def update_student():
student_id = input("Enter student ID to update: ")
if student_id in students:
name = input("Enter new student name: ")
age = input("Enter new student age: ")
students[student_id] = {"Name": name, "Age": age}
print("Student updated successfully.")
else:
print("Student not found.")
Step 8: Implement the Main Menu
def main_menu():
while True:
print("\nStudent Management System")
print("1. Accept Student")
print("2. Display Students")
print("3. Search Student")
print("4. Delete Student")
print("5. Update Student")
print("6. Exit")
choice = input("Enter your choice: ")
if choice == '1':
accept_student()
elif choice == '2':
display_students()
elif choice == '3':
search_student()
elif choice == '4':
delete_student()
elif choice == '5':
update_student()
elif choice == '6':
print("Exiting the system.")
break
else:
print("Invalid choice, please choose again.")
Step 9: Run the Program
if __name__ == "__main__":
main_menu()
Save your script as student_management_system.py and run it in your terminal or command prompt:
python student_management_system.py
Complete Python Code with Output
# Define the main dictionary to store student data
students = {}
def accept_student():
student_id = input("Enter student ID: ")
name = input("Enter student name: ")
age = input("Enter student age: ")
students[student_id] = {"Name": name, "Age": age}
print("Student added successfully!")
def display_students():
for student_id, info in students.items():
print(f"ID: {student_id}, Name: {info['Name']}, Age: {info['Age']}")
def search_student():
student_id = input("Enter student ID to search: ")
if student_id in students:
print(f"Found: ID: {student_id}, Name: {students[student_id]['Name']}, Age: {students[student_id]['Age']}")
else:
print("Student not found.")
def delete_student():
student_id = input("Enter student ID to delete: ")
if student_id in students:
del students[student_id]
print("Student deleted successfully.")
else:
print("Student not found.")
def update_student():
student_id = input("Enter student ID to update: ")
if student_id in students:
name = input("Enter new student name: ")
age = input("Enter new student age: ")
students[student_id] = {"Name": name, "Age": age}
print("Student updated successfully.")
else:
print("Student not found.")
def main_menu():
while True:
print("\nStudent Management System")
print("1. Accept Student")
print("2. Display Students")
print("3. Search Student")
print("4. Delete Student")
print("5. Update Student")
print("6. Exit")
choice = input("Enter your choice: ")
if choice == '1':
accept_student()
elif choice == '2':
display_students()
elif choice == '3':
search_student()
elif choice == '4':
delete_student()
elif choice == '5':
update_student()
elif choice == '6':
print("Exiting the system.")
break
else:
print("Invalid choice, please choose again.")
if __name__ == "__main__":
main_menu()
Output
Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 1 Enter student ID: 1 Enter student name: Ramesh Enter student age: 20 Student added successfully! Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 1 Enter student ID: 2 Enter student name: Sanjay Enter student age: 20 Student added successfully! Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 2 ID: 1, Name: Ramesh, Age: 20 ID: 2, Name: Sanjay, Age: 20 Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 3 Enter student ID to search: 1 Found: ID: 1, Name: Ramesh, Age: 20 Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 5 Enter student ID to update: 1 Enter new student name: Ram Enter new student age: 20 Student updated successfully. Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 2 ID: 1, Name: Ram, Age: 20 ID: 2, Name: Sanjay, Age: 20 Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 4 Enter student ID to delete: 2 Student deleted successfully. Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 2 ID: 1, Name: Ram, Age: 20 Student Management System 1. Accept Student 2. Display Students 3. Search Student 4. Delete Student 5. Update Student 6. Exit Enter your choice: 6 Exiting the system. === Code Execution Successful ===
Conclusion
Congratulations! You've built a simple Student Management System in Python. This project introduces you to fundamental programming concepts and Python syntax. As an extension, consider adding features like data persistence using files or databases, input validation, and a graphical user interface (GUI) using libraries like Tkinter.
Comments
Post a Comment
Leave Comment