|
| 1 | + |
| 2 | +# **CLI-Based Student Management System – Beginner's Guide** |
| 3 | + |
| 4 | +## **1. Introduction** |
| 5 | +A **Command Line Interface (CLI) Student Management System** is a simple application that allows users to manage student records efficiently using only the terminal. The system supports essential **CRUD (Create, Read, Update, Delete)** operations. |
| 6 | + |
| 7 | +This project is implemented using **Python** and focuses on key programming concepts like: |
| 8 | +- Functions & Classes |
| 9 | +- Dictionaries & Data Storage |
| 10 | +- Exception Handling |
| 11 | +- Object-Oriented Programming (OOP) |
| 12 | +- CLI-based interaction |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## **2. Project Features** |
| 17 | +This system allows users to: |
| 18 | +1. **Add Student** – Create a new student record. |
| 19 | +2. **View Students** – Display all student records. |
| 20 | +3. **Search Student** – Find a student using their roll number. |
| 21 | +4. **Update Student** – Modify student details. |
| 22 | +5. **Delete Student** – Remove a student from the system. |
| 23 | +6. **Exit** – Quit the program. |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## **3. Key Python Concepts Used** |
| 28 | +### **A. Object-Oriented Programming (OOP)** |
| 29 | +This project follows the **OOP** paradigm. We use: |
| 30 | +- **Classes** to define the structure of the program. |
| 31 | +- **Objects** to interact with student records. |
| 32 | +- **Methods (Functions inside Classes)** to perform specific tasks. |
| 33 | + |
| 34 | +#### **Class Example** |
| 35 | +```python |
| 36 | +class StudentManagement: |
| 37 | + def __init__(self): |
| 38 | + self.students = {} # Dictionary to store student records |
| 39 | +``` |
| 40 | +Here, the `StudentManagement` class contains all the functionalities of our system. |
| 41 | + |
| 42 | +### **B. Dictionaries for Data Storage** |
| 43 | +We use a **dictionary (`dict`)** to store student data: |
| 44 | +```python |
| 45 | +self.students = { |
| 46 | + "101": {"name": "John", "age": "20", "marks": "85"} |
| 47 | +} |
| 48 | +``` |
| 49 | +Each **roll number** acts as a **unique key**, and the value is another dictionary containing student details. |
| 50 | + |
| 51 | +### **C. Exception Handling** |
| 52 | +Exception handling prevents the program from crashing when unexpected input is provided. |
| 53 | + |
| 54 | +#### Example: |
| 55 | +```python |
| 56 | +try: |
| 57 | + roll_no = input("Enter roll number: ") |
| 58 | + if roll_no not in self.students: |
| 59 | + raise ValueError("Student not found!") |
| 60 | +except ValueError as e: |
| 61 | + print(f"Error: {e}") |
| 62 | +``` |
| 63 | +Here, if the roll number is not found, we manually **raise an error** using `raise ValueError("Student not found!")`. |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## **4. Explanation of CRUD Operations** |
| 68 | +### **A. Create (Add a Student)** |
| 69 | +The `add_student()` method: |
| 70 | +1. Asks for student details. |
| 71 | +2. Checks if the roll number already exists. |
| 72 | +3. Stores student details in the dictionary. |
| 73 | + |
| 74 | +#### **Code Example** |
| 75 | +```python |
| 76 | +def add_student(self): |
| 77 | + roll_no = input("Enter student roll_num: ") |
| 78 | + if roll_no in self.students: |
| 79 | + print("Student already exists!") |
| 80 | + return |
| 81 | + name = input("Enter student name: ") |
| 82 | + age = input("Enter student age: ") |
| 83 | + marks = input("Enter student marks: ") |
| 84 | + |
| 85 | + self.students[roll_no] = {"name": name, "age": age, "marks": marks} |
| 86 | + print("Student added successfully!") |
| 87 | +``` |
| 88 | + |
| 89 | +### **B. Read (View Students)** |
| 90 | +The `view_students()` method: |
| 91 | +1. Checks if any students exist. |
| 92 | +2. Loops through the dictionary and prints student details. |
| 93 | + |
| 94 | +#### **Code Example** |
| 95 | +```python |
| 96 | +def view_students(self): |
| 97 | + if not self.students: |
| 98 | + print("No data exists") |
| 99 | + return |
| 100 | + print("\n--- STUDENT LIST ---\n") |
| 101 | + for roll_no, data in self.students.items(): |
| 102 | + print(f"Roll No.: {roll_no}, Name: {data['name']}, Age: {data['age']}, Marks: {data['marks']}") |
| 103 | +``` |
| 104 | + |
| 105 | +### **C. Search Student** |
| 106 | +The `search_student()` method: |
| 107 | +1. Takes a roll number as input. |
| 108 | +2. Checks if it exists in the dictionary. |
| 109 | +3. Displays student details if found. |
| 110 | + |
| 111 | +#### **Code Example** |
| 112 | +```python |
| 113 | +def search_student(self): |
| 114 | + roll_no = input("Enter roll number: ") |
| 115 | + student = self.students.get(roll_no) |
| 116 | + if student: |
| 117 | + print(f"Found: {student}") |
| 118 | + else: |
| 119 | + print("Student not found") |
| 120 | +``` |
| 121 | + |
| 122 | +### **D. Update Student Details** |
| 123 | +The `update_details()` method: |
| 124 | +1. Asks for the roll number. |
| 125 | +2. If found, asks for new details (allows skipping updates). |
| 126 | +3. Updates the dictionary. |
| 127 | + |
| 128 | +#### **Key Concept: Default Values using `or`** |
| 129 | +```python |
| 130 | +name = input("Enter New Name (leave blank to keep existing): ") or self.students[roll_no]["name"] |
| 131 | +``` |
| 132 | +- If the user **enters a value**, it is stored. |
| 133 | +- If the user **presses Enter (leaving blank)**, it keeps the existing value. |
| 134 | + |
| 135 | +#### **Code Example** |
| 136 | +```python |
| 137 | +def update_details(self): |
| 138 | + roll_no = input("Enter roll number: ") |
| 139 | + if roll_no not in self.students: |
| 140 | + print("Student not found!") |
| 141 | + return |
| 142 | + name = input("Enter New Name (leave blank to keep existing): ") or self.students[roll_no]["name"] |
| 143 | + age = input("Enter New Age (leave blank to keep existing): ") or self.students[roll_no]["age"] |
| 144 | + marks = input("Enter New Marks (leave blank to keep existing): ") or self.students[roll_no]["marks"] |
| 145 | + |
| 146 | + self.students[roll_no] = {"name": name, "age": age, "marks": marks} |
| 147 | + print("Student updated successfully!") |
| 148 | +``` |
| 149 | + |
| 150 | +### **E. Delete a Student** |
| 151 | +The `delete_student()` method: |
| 152 | +1. Takes a roll number as input. |
| 153 | +2. Deletes the entry from the dictionary. |
| 154 | + |
| 155 | +#### **Code Example** |
| 156 | +```python |
| 157 | +def delete_student(self): |
| 158 | + roll_no = input("Enter roll number: ") |
| 159 | + if roll_no in self.students: |
| 160 | + del self.students[roll_no] |
| 161 | + print("Student details removed!") |
| 162 | + else: |
| 163 | + print("Student not found") |
| 164 | +``` |
| 165 | + |
| 166 | +--- |
| 167 | + |
| 168 | +## **5. CLI Menu System** |
| 169 | +A `while True` loop is used to create a **menu-driven interface**: |
| 170 | +```python |
| 171 | +def run(self): |
| 172 | + while True: |
| 173 | + print("\n1. Add Student\n2. View Students\n3. Search Student\n4. Update Student\n5. Delete Student\n6. Exit") |
| 174 | + choice = input("Enter your choice: ") |
| 175 | + |
| 176 | + if choice == "1": |
| 177 | + self.add_student() |
| 178 | + elif choice == "2": |
| 179 | + self.view_students() |
| 180 | + elif choice == "3": |
| 181 | + self.search_student() |
| 182 | + elif choice == "4": |
| 183 | + self.update_details() |
| 184 | + elif choice == "5": |
| 185 | + self.delete_student() |
| 186 | + elif choice == "6": |
| 187 | + print("Exiting...") |
| 188 | + break |
| 189 | + else: |
| 190 | + print("Invalid choice! Please try again.") |
| 191 | +``` |
| 192 | +### **Key Points:** |
| 193 | +- Users **choose an option** (1-6). |
| 194 | +- Corresponding **method is executed**. |
| 195 | +- **Loop continues** until the user selects **Exit (6)**. |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +## **6. Running the Program** |
| 200 | +To run the program only when executed directly: |
| 201 | +```python |
| 202 | +if __name__ == "__main__": |
| 203 | + app = StudentManagement() |
| 204 | + app.run() |
| 205 | +``` |
| 206 | +This ensures that the script **only runs when executed**, not when imported. |
| 207 | + |
| 208 | +--- |
| 209 | + |
| 210 | +## **7. Summary of Key Takeaways** |
| 211 | +✅ **Used Python Classes & OOP** |
| 212 | +✅ **Implemented CRUD Operations** |
| 213 | +✅ **Used Dictionaries for Data Storage** |
| 214 | +✅ **Handled Exceptions Gracefully** |
| 215 | +✅ **Built a CLI-Based Interactive System** |
| 216 | + |
| 217 | +--- |
| 218 | + |
| 219 | +## **8. Possible Enhancements** |
| 220 | +- **Store Data Permanently** (Using JSON or SQLite) |
| 221 | +- **Add More Fields** (e.g., Address, Course) |
| 222 | +- **Implement Sorting & Filtering** |
| 223 | +- **GUI Version (Tkinter or Flask Web App)** |
| 224 | + |
| 225 | +--- |
| 226 | + |
0 commit comments