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

School Management System Code

The document contains a Python script for a school management system that allows adding and removing students and teachers, as well as displaying them. It includes functions for database operations using MySQL and a simple text-based menu for user interaction. There are several syntax errors and typos throughout the code that need to be corrected for proper functionality.

Uploaded by

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

School Management System Code

The document contains a Python script for a school management system that allows adding and removing students and teachers, as well as displaying them. It includes functions for database operations using MySQL and a simple text-based menu for user interaction. There are several syntax errors and typos throughout the code that need to be corrected for proper functionality.

Uploaded by

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

SOURCE CODE

import [Link]
from getpass import getpass

# Database connection
db [Link]
host"lacalhost",

Usereoo'
database'cbse

cursor = [Link])

#Function to add a new student


def add_student():
first name =input("Enter student's first name:")
last_name input("'Enter student's last name:")
roll_number int(input("Enter student's roll number:"))
[Link]("INSERT INTO students (first_name, last_narne, roll_number) VALUES (%s, %s, %5)",
(first_name, last_name, rol_number))
[Link]()
print("Student added successfulyl")
WFunction to remove a student
def temove student):
roll_number int(input("Enter the roll number of the student to remove:"))
[Link]("DELETE FROM students WHERE roll number s", (roll_number,))
[Link]()
print("Student removed successfully!")
# Function to add a new teacher
def add _teacher):
ut("Enter teacher's first name:

ter the subiect they teach: ")


[Link]("INSERT
cusor.e INTO teachers (firstname, last_name, sutbject) VALUES (Ns, , Ns)",
(first rname, last_name, subject))
db,commit()
print("Teacher added successtully")

# Function to removea teacher


def remove teacher):

teacher_id =int(input[' Enter the iD of the teacher to remove:"))


[Link]("DELETE FROM teschers WHERE Id - 9%s", (teacher_id.)
db,commit()
print("Teacher removed successfully!")
-WELCOME TO THE SCHOOL MANAGEMENT SYrSTEM
MADE BY ØaAgHSNEH KAUR

MAIN MENU

1 Add New Student 2. Remove Student

3. Add New Teacher 4, Remove Teacher

5. Add Feedback 6. Display Students


7. Display Teachers 8. Logout

choice input("Enter your choice (1-8):")

it choice 1:
aoo_stucento

etf choicet student


add teacher)
eiif choice-4:
remove teacher()
elif cholce '5:
add feedback()
elf cholce6:
dsplay students()
elif choice7:
display_teachers()
elif choice '8:
print("Logging out "]
break
else:
print("Invalid choice. Try again.)
else
printt"Login failed. Please try again ")
elif choice '3:
print("Exiting the Schoalmanagement system, GOoDBYE)
break

Common questions

Powered by AI

The school management system in Source 1 lacks explicit error handling, such as try-except blocks, to manage exceptions during database operations. This absence means that any errors encountered, such as connection failures, syntax errors in SQL statements, or unexpected input values, could cause the program to terminate unexpectedly. Effective error management should include exception handling to catch specific errors; logging mechanisms to record errors for later analysis; and user notifications to offer guidance when issues occur. Implementing these elements would enhance system robustness and user experience .

The use of command-line inputs in school management systems offers simplicity and requires fewer system resources, allowing quick development and efficient execution, especially for users familiar with terminal environments. However, disadvantages include a steep learning curve for users unfamiliar with command lines, lack of visual engagement and feedback which can improve user experience, and reduced accessibility features that modern GUIs provide. GUI-based systems, though potentially more resource-intensive, can offer enhanced usability, accessibility, and aesthetically engaging interfaces that facilitate user interactions with intuitive design elements .

To add a new student to the database in the school management system, the system follows these steps: First, it prompts the user to input the student's first name, last name, and roll number. These inputs are collected using standard input functions. Then, it executes an SQL INSERT command to add these values to the 'students' table in the database. The SQL query used is: "INSERT INTO students (first_name, last_name, roll_number) VALUES (%s, %s, %5)", where the placeholders are the collected input values. Finally, the system commits this transaction to the database and prints a confirmation message indicating the student has been successfully added .

Executing raw SQL queries in the system, as seen where insertions and deletions are made, can expose it to SQL injection attacks, making it vulnerable to unauthorized data access or manipulation. Additionally, using hardcoded SQL strings embedded in the codebase impacts maintainability by making changes difficult, especially as the system grows. Best practices to improve security include using parameterized queries and prepared statements, which prevent SQL injection by separating SQL logic from data inputs. Furthermore, adopting ORM frameworks can enhance maintainability by abstracting complex SQL syntax into higher-level code that is easier to manage and refactor .

The system returns an 'Invalid choice. Try again' message when the user inputs a command that does not match any predefined options in the main menu. This is handled using an 'else' clause after checking all valid input choices from 1 to 8 using ‘elif’ statements. When none of the 'elif' conditions is true, indicating the input is invalid, the system executes the 'else' block that prints the message and prompts the user to input a new choice .

The system ensures data persistence by committing every change to the database after executing an SQL command. For example, when a student or teacher is added or removed, the system calls `db.commit()` immediately after the SQL `INSERT` or `DELETE` command is executed. This commit action applies the transaction, making the changes permanent in the database .

The user input process in the system currently lacks validation checks, which can lead to invalid data entries such as non-numeric roll numbers or undefined teacher subjects. Moreover, there is no error handling for cases where the database operations might fail (e.g., entering a duplicate roll number). Improvements include incorporating input validation functions to check data types and ranges before executing database commands, using exception handling to catch and manage database errors gracefully, and providing user feedback on input errors. Adding sanitization mechanisms would further strengthen security by preventing malformed data from being processed .

In the context of the school management system, feedback likely pertains to user interactions or system performance improvements although specifics are not detailed in the source. The system includes an option to 'Add Feedback', suggesting a functionality where users can input comments or suggestions regarding system usability or performance. Implementation would involve collecting user input, possibly storing it in a dedicated database table, and potentially using it for system analysis and enhancements. The actual code for feedback handling isn't provided in the source, indicating it might be planned or a placeholder for future development .

Removing teachers or students by unique identifiers such as ID or roll numbers could lead to potential data integrity issues, especially if these records have foreign key dependencies in other tables (e.g., attendance or grading records). The complications arise when deletions cause orphaned records or data inconsistencies. To mitigate these, implementing foreign key constraints with cascading delete or using soft deletions (marking records as inactive instead of permanent removal) can maintain data integrity. Additionally, ensuring referential integrity through database constraints and thoroughly testing the deletion operations can prevent unintended data loss .

To enhance scalability in this school management system, structural changes could include modularizing code to separate database logic from business logic, implementing a more robust database management system capable of handling higher volumes of data and user connections, and decoupling functional components to allow distributed processing. Transitioning to a microservices architecture can facilitate independent scaling of different system parts as needed. Moreover, introducing load balancing and implementing caching strategies can optimize performance as the user base grows .

You might also like