0% found this document useful (0 votes)
12 views19 pages

School Management System in Python

This Python code connects to a MySQL database called "schoolmgt" and provides functions for student, employee, fee, and attendance management within a school management system. The main menu allows the user to select an option to view and modify existing records or add/update/delete new records for students, employees, fees, or attendance data in the database tables.

Uploaded by

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

School Management System in Python

This Python code connects to a MySQL database called "schoolmgt" and provides functions for student, employee, fee, and attendance management within a school management system. The main menu allows the user to select an option to view and modify existing records or add/update/delete new records for students, employees, fees, or attendance data in the database tables.

Uploaded by

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

PYTHON CODE

import [Link] as sq

#PROGRAM FOR DATABASE CONNECTIVITY

def connect():

db=[Link](host='localhost',user='root',database='schoolmgt')

if db.is_connected==False:

print("notconnected")

return db

#PROGRAM FOR USING SCHOOL MANAGEMENT

def select():

print("-----------------------WELCOME TO SCHOOL
MANAGEMENT-------------------------")

print("[Link] MANAGEMENT")

print("[Link] MANAGEMENT")

print("[Link] FEE")

print("[Link] MANAGEMENT")

print("[Link] SCHOOL DETAILS")

ch=int(input("enter your choice(1-5):-"))

if ch==1:
PYTHON CODE

print("\n------------------WELCOME TO STUDENT
MANAGEMENT------------------\n")

print("[Link] ADMISSION")

print("[Link] DETAILS")

print("[Link] TC")

print("\nEXISTING RECORDS ARE\n")

def displayst():

con=connect()

cur=[Link]()

[Link]("select * from st")

for i in [Link]():

admno=i[0]

name=i[1]

clas=i[2]

city=i[3]

dob=i[4]

print("(admno=%d,name=%s,class=%s,city=%s,dob=%s)"%
(admno,name,clas,city,dob))

displayst()

c=input("enter your choice(a-c):-")

if c=='a':

def insertst():
PYTHON CODE

name=input("enter student name:-")

admno=int(input("enter admission number:-"))

clas=input("enter class:-")

city=input("enter city:-")

dob=input("enter date of birth(year-month-time):-")

con=connect()

cur=[Link]()

[Link]("insert into
st(name,admno,class,city,dob)values('%s','%d','%s','%s','%s')"%
(name,admno,clas,city,dob))

[Link]()

insertst()

print("MODIFIED RECORDS ARE")

displayst()

elif c=='b':

def updatest():

con=connect()

cur=[Link]()

clas=input("ENTER NEW CLASS:-")


PYTHON CODE

admno=int(input("ENTER ADMISSION NO. :-"))

[Link]("update st set class=%s where admno=%d"%


(clas,admno))

[Link]()

updatest()

print("\nMODIFIED DETAILS ARE:-\n")

displayst()

elif c=='c':

def deletest():

con=connect()

cur=[Link]()

admno=int(input("ENTER ADMISSION NO. TO BE


DELETED:-"))

ans=input("ARE YOU SURE YOU WANT TO DELETE(y/n):-")

if ans=='y' or ans=='Y':

[Link]("delete from st where admno=%d"%(admno))

[Link]()

deletest()

print("\nMODIFIED DETAILS ARE:-\n")


PYTHON CODE

displayst()

elif ch==2:

print("/n------------------WELCOME TO EMPLOYEE------------------/n")

print("a. NEW EMPLOYEE")

print("b. UPDATE STAFF DETAILS")

print("c. DELETE EMPLOYEE")

e=input("enter your choice(a-c)")

print("\nEXISTING RECORDS ARE\n")

def displayemp():

con=connect()

cur=[Link]()

[Link]("select * from emp")

for i in [Link]():

empno=i[0]

name=i[1]

job=i[2]

hiredate=i[3]

print("(empno=%d,name=%s,job=%s,hiredate=%s)"%
(empno,name,job,hiredate))

displayemp()
PYTHON CODE

if e=='a':

def insertemp():

empno=int(input("enter empno:-"))

name=input("enter employee name:-")

job=input("enter designation:-")

hiredate=input("enter hiredate(year-month-time):-")

con=connect()

cur=[Link]()

[Link]("insert into
emp(empno,name,job,hiredate)values('%d','%s','%s','%s')"%
(empno,name,job,hiredate))

[Link]()

insertemp()

def displayemp():

con=connect()

cur=[Link]()

[Link]("select * from emp")

for i in [Link]():

empno=i[0]

name=i[1]
PYTHON CODE

job=i[2]

hiredate=i[3]

print("(empno=%d,name=%s,job=%s,hiredate=%s)"%
(empno,name,job,hiredate))

print("\nMODIFIED RECORDS ARE\n")

displayemp()

elif e=='b':

def updateemp():

con=connect()

cur=[Link]()

job=input("ENTER NEW JOB:-")

empno=int(input("ENTER EMPLOYEE NO:-"))

[Link]("update emp set job='%s' where empno=%d"%


(job,empno))

[Link]()

updateemp()

print("\nMODIFIED RECORDS ARE\n")

displayemp()
PYTHON CODE

elif e=='c':

def deleteemp():

con=connect()

cur=[Link]()

d=int(input("ENTER EMPNO TO BE DELETED:-"))

ans=input("ARE YOU SURE YOU WANT TO DELETE


RECORD(y/n):-")

if ans=='y' or ans=='Y':

[Link]("delete from emp where empno=%d"%(d))

[Link]()

deleteemp()

print("\nMODIFIED RECORDS ARE\n")

displayemp()

elif ch==3:

print("\n--------------WELCOME TO DISPLAY FEES------------------\n")

print("[Link] FEES")

print("[Link] FEES")

print("[Link] FEES")
PYTHON CODE

print("\n EXISTING RECORDS ARE:-\n")

def displayfee():

con=connect()

cur=[Link]()

[Link]("select * from fees")

for i in [Link]():

admno=i[0]

fees=i[1]

monthunpaid=i[2]

print("(admno=%d,fees=%f,monthunpaid=%s)"%
(admno,fees,monthunpaid))

displayfee()

f=input("ENTER YOUR CHOICE(a-c):-")

if f=='a':

def insertfee():

admno=int(input("ENTER ADMISSION NO. :-"))

fees=float(input("ENTER AMOUNT OF FEES TO BE PAID:-"))

monthunpaid=input("ENTER MONTH OF WHICH FEES TO BE


PAID:-")
PYTHON CODE

con=connect()

cur=[Link]()

[Link]("insert into fees(admno,fees,monthunpaid)


values ('%d','%f','%s')"%(admno,fees,monthunpaid))

[Link]()

insertfee()

print("\nMODIFIED RECORDS ARE:-\n")

displayfee()

elif f=='b':

def updatefee():

month=input("ENTER MONTH TO BE UPDATED:-")

admno=int(input("ENTER ADMISSION NO.:-"))

con=connect()

cur=[Link]()

[Link]("update fees set monthunpaid='%s'where


admno=%d"%(month,admno))

[Link]()
PYTHON CODE

updatefee()

print("\nMODIFIED RECORDS ARE\n")

displayfee()

elif f=='c':

def deletefee():

admo=int(input("ENTER ADMISSION NO.:-"))

a=input("ENTER ARE YOU SURE YOU WANT TO EXEMPT


FEE(y/n):-")

con=connect()

cur=[Link]()

if a=='Y' or a=='y':

[Link]("delete from fees where admno=%d"%(admo))

[Link]()

deletefee()

print("\nMODIFIED RECORDS ARE\n")

displayfee()
PYTHON CODE

elif ch==4:

print("\n------------------WELCOME TO ATTENDANCE
MANAGEMENT------------------\n")

print("[Link] DETAILS")

print("[Link] DETAILS")

print("[Link] DETAILS")

print("\nEXISTING DETAILS ARE:-")

def displayatt():

con=connect()

cur=[Link]()

[Link]("select * from attendance")

for i in [Link]():

admno=i[0]

name=i[1]

present=i[2]

totalpresent=i[3]

per=i[4]

print("(admno=%d,name=%s,present=%d,totalpresent=
%d,per=%f)"%(admno,name,present,totalpresent,per))

displayatt()

a=input("enter your choice")


PYTHON CODE

if a=='a':

def insertatt():

admno=int(input("ENTER ADMISSION NO.:-"))

name=input("ENTER STUDENT NAME:-")

present=int(input("ENTER CLASS ATTENDED DURING THE


YEAR:-"))

totalpresent=int(input("ENTER TOTAL CLASS ATTENDED


DURING THE YEAR:-"))

per=float(input("ENTER PERCENTAGE:-"))

con=connect()

cur=[Link]()

[Link]("insert into
attendance(admno,name,present,totalpresent,per) values
('%d','%s','%d','%d','%f')"%(admno,name,present,totalpresent,per))

[Link]()

insertatt()

print("\nMODIFIED DETAILS ARE:-\n")

displayatt()

elif a=='b':

def updateatt():
PYTHON CODE

present=int(input("ENTER CLASS ATTENDED DURING THE


YEAR:-"))

per=float(input("ENTER PERCENTAGE:-"))

admno=int(input("ENTER ADMISSION NO.:-"))

con=connect()

cur=[Link]()

[Link]("update attendance set present='%d',per='%f'


where admno='%d'"%(present,per,admno))

[Link]()

updateatt()

print("\nMODIFIED DETAILS ARE:-\n")

displayatt()

elif a=='c':

def deleteexam():

admno=int(input("ENTER ADMISSION NO.:-"))

f=input("ARE YOU SURE YOU WANT TO DELETE(y/n):-")

con=connect()

cur=[Link]()

if f=='y' or f=='Y':
PYTHON CODE

[Link]("delete from attendance where


admno='%d'"%(admno))

[Link]()

deleteexam()

print("\nMODIFIED DETAILS ARE:-\n")

displayatt()

elif ch==5:

print("\n------------------WELCOME TO DISPLAY SCHOOL RELATED


DETAILS------------------\n")

print("[Link] DETAILS")

print("[Link] DETAILS")

print("[Link] DETAILS")

print("\nEXISTING DETAILS ARE:-\n")

def displaysc():

con=connect()

cur=[Link]()

[Link]("select * from school")

for i in [Link]():

sid=i[0]

sname=i[1]
PYTHON CODE

noofstudent=i[2]

noofemployee=i[3]

nooflabs=i[4]

print("(id=%d,sname='%s',noofstudent=%d,noofemployee=
%d,nooflabs=%d)"%(sid,sname,noofstudent,noofemployee,nooflabs))

displaysc()

s=input("ENTER YOUR CHOICE")

if s=='a':

def insertsc():

sid=int(input("ENTER SCHOOL ID:-"))

sname=input("ENTER SCHOOL NAME:-")

noofstudent=int(input("ENTER NUMBER OF STUDENT:-"))

noofemployee=int(input("ENTER NUMBER OF EMPLOYEE:-"))

nooflabs=int(input("ENTER NUMBER OF LABS:-"))

con=connect()

cur=[Link]()

[Link]("insert into
school(id,sname,noofstudent,noofemployee,nooflabs)values(%d,'%s',
%d,%d,%d)"%(sid,sname,noofstudent,noofemployee,nooflabs))

[Link]()
PYTHON CODE

insertsc()

print("\nMODIFIED DETALIS ARE:-\n")

displaysc()

elif s=='b':

def updatesc():

noofstudent=int(input("ENTER NUMBER OF STUDENT:-"))

noofemployee=int(input("ENTER NUMBER OF EMPLOYEE:-"))

nooflabs=int(input("ENTER NUMBER OF LABS:-"))

sid=int(input("ENTER SCHOOL ID:-"))

con=connect()

cur=[Link]()

[Link]("update school set noofstudent=


%d,noofemployee=%d,nooflabs=%d where id=%d"%
(noofstudent,noofemployee,nooflabs,sid))

[Link]()

updatesc()

print("\nMODIFIED DETALIS ARE:-\n")

displaysc()
PYTHON CODE

elif s=='c':

def deletesc():

sid=int(input("ENTER SCHOOL ID:-"))

con=connect()

cur=[Link]()

[Link]("delete from school where id=%d"%(sid))

[Link]()

deletesc()

print("\nMODIFIED DETALIS ARE:-\n")

displaysc()

d=input("DO YOU WANT TO USE THE DATABASE AGAIN(y/n)")

if d=='y'or d=='Y':

select()

elif d=='n' or d=='N':

print("\n------------------THANKS FOR VISITING SCHOOL


MANAGEMENT------------------\n")
PYTHON CODE

select()

Common questions

Powered by AI

To ensure confidentiality of user credentials during database connection, it is essential to avoid hardcoding credentials directly in the source code, as seen with 'user' and 'password' parameters. Instead, the program could retrieve credentials from secure configuration files or environment variables. Implementing encryption methods to store these credentials and using secure protocols (e.g., SSL/TLS) to establish database connections can further enhance security by protecting sensitive information from being exposed in transit or at rest .

The program ensures data fidelity by confirming the deletion of records through user prompts. For each delete operation across tables like 'st', 'emp', 'fees', and 'attendance', the program asks for user confirmation ('ARE YOU SURE YOU WANT TO DELETE(y/n)'), and the deletion proceeds only if the response is affirmative ('y' or 'Y'). This precaution minimizes accidental deletions and maintains data integrity .

The current system, structured as a command-line interface with procedural logic and without concurrency handling, may face scalability issues as the number of records grows. All operations depend on a direct connection to the database without handling multiple connections or concurrent users effectively. To improve scalability, the system could be re-engineered with an asynchronous or multithreaded architecture, use of an ORM (Object-Relational Mapping) for better data management, implementation of pagination for data retrieval, and a more robust front-end framework for better user interaction and responsiveness .

Using raw string interpolation to construct SQL queries, as seen in this program, poses significant security risks, notably SQL injection. Attackers could manipulate the input to execute arbitrary SQL commands. To mitigate this, parameterized queries or prepared statements should be used instead of directly embedding input values into query strings. For example, replacing 'cur.execute(...)' with 'cur.execute(sql, params)' can prevent unauthorized code execution by treating input values strictly as data rather than executable SQL code .

If a connection to the database cannot be established, the system is designed to print 'notconnected'. This is a minimal form of error messaging that does not provide detailed insights or guidance on resolving the issue, which may lead to user frustration. Enhancing error handling by providing more informative messages, debugging options, or automatic retry/alternative database connection strategies could significantly improve the user experience by guiding them to troubleshoot connectivity issues effectively .

The script uses inconsistent naming conventions, mixing lowercase, underscores, and abbreviated forms (e.g., 'select()', 'updatest()', 'deletest()'). Such inconsistency can reduce code readability by making it harder for developers to predict function names or understand code flow quickly. Adopting a consistent naming convention, such as using descriptive names and separating words with underscores or following a CamelCase style, would enhance the code's readability and maintainability, facilitating easier collaboration and future updates .

To track the execution time of each query, you could wrap database operations within a timing function using the `time` library. For instance, by capturing timestamps before and after query execution with `time.time()`, then logging the difference, developers can identify slow operations. This is important for performance optimization, enabling developers to focus on refining slow queries or database restructuring to reduce latency, thus improving overall system efficiency and user experience .

The school management system handles different domain operations by organizing them into specific, clearly defined sections within the program. It uses a structured sequence of if-elif statements to present options (e.g., student management, employee management, fee display) to the user, each directing to further sub-operations such as adding, updating, or deleting records. This hierarchical command-line interface helps in organizing functionality logically and allows easy navigation through the different operations of the system, applying a procedural programming strategy based on user choices .

The 'commit' method is used to save the changes made by the SQL queries in the database. In the context of this school management system, after executing SQL operations such as inserting, updating, or deleting records in tables like 'st', 'emp', 'fees', etc., 'commit' ensures that the changes are permanently applied to the database. Without 'commit', any changes would be lost once the database connection is closed, making it crucial for maintaining data consistency and integrity .

The student management system implements modularity by defining separate functions for each operation, such as 'insertst()', 'updatest()', 'deletest()', and 'displayst()' for handling student records. This modular design separates concerns, makes the code more maintainable, and allows for easier testing and debugging of individual components without affecting the entire system. It also enhances code reusability, where specific operations can be invoked as needed without redundancy .

You might also like