0% found this document useful (0 votes)
13 views3 pages

School Management System Code

Uploaded by

abhij7262
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

School Management System Code

Uploaded by

abhij7262
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import pickle

class SchoolManagementSystem:
def __init__(self):
[Link] = {}
[Link] = {}
[Link] = {}

def add_student(self, student_id, name, age, grade):


[Link][student_id] = {"name": name, "age": age, "grade": grade}

def add_teacher(self, teacher_id, name, subject):


[Link][teacher_id] = {"name": name, "subject": subject}

def add_class(self, class_id, teacher_id, subject, students):


if teacher_id in [Link]:
[Link][class_id] = {
"teacher": [Link][teacher_id],
"subject": subject,
"students": [[Link][student_id] for student_id in students if student_id in
[Link]]
}

def get_student(self, student_id):


return [Link](student_id, "Student not found")

def get_teacher(self, teacher_id):


return [Link](teacher_id, "Teacher not found")

def get_class(self, class_id):


return [Link](class_id, "Class not found")

def record_attendance(self, class_id, student_id, status):


if class_id in [Link] and any(student["name"] == [Link][student_id]
["name"] for student in [Link][class_id]["students"]):
[Link][class_id].setdefault("attendance", {})[student_id] = status
else:
return "Class or student not found"

def calculate_fees(self, student_id, base_fee):


student = self.get_student(student_id)
if isinstance(student, dict):
fee = base_fee
if student["grade"] > 5:
fee *= 1.2
return f"Fees for {student['name']}: ${fee}"
return student

def save_data(self, filename):


with open(filename, "wb") as file:
[Link](self, file)

@staticmethod
def load_data(filename):
try:
with open(filename, "rb") as file:
return [Link](file)
except (FileNotFoundError, EOFError):
return SchoolManagementSystem()
def main():
filename = "school_data.pkl"
school = SchoolManagementSystem.load_data(filename)

while True:
print("\n--- School Management System ---")
print("1. Add Student")
print("2. Add Teacher")
print("3. Add Class")
print("4. View Student")
print("5. View Teacher")
print("6. View Class")
print("7. Record Attendance")
print("8. Calculate Fees")
print("9. Save and Exit")

choice = int(input("Enter your choice: "))

if choice == 1:
student_id = int(input("Enter student ID: "))
name = input("Enter student name: ")
age = int(input("Enter student age: "))
grade = int(input("Enter student grade: "))
school.add_student(student_id, name, age, grade)

elif choice == 2:
teacher_id = int(input("Enter teacher ID: "))
name = input("Enter teacher name: ")
subject = input("Enter subject: ")
school.add_teacher(teacher_id, name, subject)

elif choice == 3:
class_id = input("Enter class ID: ")
teacher_id = int(input("Enter teacher ID: "))
subject = input("Enter subject: ")
student_ids = list(map(int, input("Enter student IDs (comma separated):
").split(',')))
school.add_class(class_id, teacher_id, subject, student_ids)

elif choice == 4:
student_id = int(input("Enter student ID to view: "))
print(school.get_student(student_id))

elif choice == 5:
teacher_id = int(input("Enter teacher ID to view: "))
print(school.get_teacher(teacher_id))

elif choice == 6:
class_id = input("Enter class ID to view: ")
print(school.get_class(class_id))

elif choice == 7:
class_id = input("Enter class ID: ")
student_id = int(input("Enter student ID: "))
status = input("Enter attendance status (Present/Absent): ")
print(school.record_attendance(class_id, student_id, status))
elif choice == 8:
student_id = int(input("Enter student ID for fee calculation: "))
base_fee = float(input("Enter base fee amount: "))
print(school.calculate_fees(student_id, base_fee))

elif choice == 9:
school.save_data(filename)
print("Data saved. Exiting...")
break

else:
print("Invalid choice. Try again.")

if __name__ == "__main__":
main()

Common questions

Powered by AI

The system requires a valid teacher ID that exists in the teachers' dictionary to add a new class. It then assigns the teacher's information, the subject, and a list of students, filtered from the students' dictionary, to the new class. If the teacher ID is not found in the teachers' dictionary, the class will not be created .

The system checks for both the existence of the class and the presence of the student within it before recording attendance. However, this approach could lead to issues if there are errors in class or student data integrity. Additionally, the lack of detailed attendance reports or historical attendance tracking may limit the system's ability to monitor attendance trends effectively .

The fee calculation method applies a 20% surcharge for students in grades higher than 5, effectively increasing the financial burden on families with older students. This approach may be justified by the potential increased costs associated with higher education but could also discourage enrollment in higher grades or create financial strain for some families .

Teachers are associated with specific subjects upon entry, allowing for organized class assignment and subject specialization. However, this rigid structure may not easily accommodate teachers who can teach multiple subjects or those transitioning between subjects. Adjusting the system to support multiple specializations per teacher could provide greater flexibility .

When adding a class, the system validates that the teacher ID provided exists in its teachers directory. It then associates the class with the corresponding teacher's details, ensuring that only registered teachers can be linked to classes. This method ensures that each class is managed by a recognized teacher .

The system uses Python's pickle module for data serialization and stores data in a file. While this method ensures data persistence across program executions, it carries the risk of data corruption or loss if the file is improperly handled. Additionally, reliance on file-based storage lacks the robustness and security features of a database system .

The system attempts to load school data from a file using pickle. If the file is not found or empty, a new instance of the system is created. Although this ensures continuity, it bypasses any validation, potentially leading to the use of outdated or erroneous data. Furthermore, pickle's security vulnerabilities, such as code execution risks when unpickling untrusted data, remain a concern .

The system uses the get method with a default return value of 'Student not found' when a student ID is provided that does not exist in the students dictionary. This approach allows the system to handle such errors gracefully, providing clear feedback without disrupting the program flow .

The system retrieves data using dictionary lookups, which is efficient for small to medium-sized datasets, ensuring quick access to entities like students, teachers, and classes. However, as the scale of data increases, reliance solely on dictionaries might not be optimal due to memory limitations and lack of advanced query capabilities, potentially impacting performance in large-scale applications .

The main menu presents options for managing students, teachers, classes, attendance, and fees interactively. Users select options by entering a number corresponding to their choice; however, it relies on command-line inputs, which could be confusing for non-technical users. Enhancements could include implementing a graphical user interface (GUI) for more intuitive navigation and adding help prompts to clarify actions associated with each menu option .

You might also like