0% found this document useful (0 votes)
26 views

Hamza

The document describes a school management system using Python and MySQL. It includes functions for: 1. Managing student, employee, fee, and exam data through tables in a MySQL database. 2. Providing menu options to users for performing CRUD operations on each data type. 3. Defining functions to insert, display, update, and delete records from the relevant tables. The system allows managing key aspects of a school through an interactive Python interface connected to backend MySQL tables for student, employee, fee, and exam information. Functions handle common data operations for each entity stored in the tables.

Uploaded by

Saba Fahim
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)
26 views

Hamza

The document describes a school management system using Python and MySQL. It includes functions for: 1. Managing student, employee, fee, and exam data through tables in a MySQL database. 2. Providing menu options to users for performing CRUD operations on each data type. 3. Defining functions to insert, display, update, and delete records from the relevant tables. The system allows managing key aspects of a school through an interactive Python interface connected to backend MySQL tables for student, employee, fee, and exam information. Functions handle common data operations for each entity stored in the tables.

Uploaded by

Saba Fahim
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
You are on page 1/ 23

Table Structure: As per screenshots:

Table: Student

Table: Emp
Table: Fee

Table:Exam
Python Code
import os
import platform
import mysql.connector
def selection():
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
print('-----------------------------------\WELCOME TO SCHOOL MANAGEMENT SYSTEM\-----------------------
------------')
print("1.STUDENT MANAGEMENT")
print("2.EMPLOYEE MANAGEMENT")
print("3.FEE MANAGEMENT")
print("4.EXAM MANAGEMENT")

ch=int(input("\nEnter ur choice (1-4) : "))


if ch==1:
print('\nWELCOME TO STUDENT MANAGEMENT SYSTEM\n')
print('a. NEW ADMISSION')
print('b. UPDATE STUDENT DETAILS')
print('c. ISSUE TC')
c=input("Enter ur choice (a-c) : ")
print('\nInitially the details are..\n')
display1()
if c=='a':
insert1()
print('\nModified details are..\n')
display1()
if c=='b':
update1()
print('\nModified details are..\n')
display1()
if c=='c':
delete1()
print('\nModified details are..\n')
display1()
else:
print('Enter correct choice...!!')
if ch==2:
print('WELCOME TO EMPLOYEE MANAGEMENT SYSTEM')
print('a.NEW EMPLOYEE')
print('b.UPDATE STAFF DETAILS')
print('c.DELETE EMPLOYEE')
c=input("Enter ur choice : ")
if c=='a':
insert2()
print('\nModified details are..\n')
display2()
elif c=='b':
update2()
print('\nModified details are..\n')
display2()
elif c=='c':
delete2()
print('\nModified details are..\n')
display2()
else:
print('Enter correct choice...!!')
if ch==3:
print('WELCOME TO FEE MANAGEMENT SYSTEM')
print('a.NEW FEE')
print('b.UPDATE FEE')
print('c.EXEMPT FEE')
c=input("Enter ur choice : ")
if c=='a':
insert3()
elif c=='b':
update3()
elif c=='c':
delete3()
else:
print('Enter correct choice...!!')
if ch==4:
print('WELCOME TO EXAM MANAGEMENT SYSTEM')
print('a.EXAM DETAILS')
print('b.UPDATE DETAILS ')
print('c.DELETE DETAILS')
c=input("Enter ur choice : ")
if c=='a':
insert4()
elif c=='b':
update4()
elif c=='c':
delete4()
else :
print('Enter correct choice..!!')

def insert1():
sname=input("Enter Student Name : ")
admno=int(input("Enter Admission No : "))
dob=input("Enter Date of Birth(yyyy-mm-dd): ")
cls=input("Enter class for admission: ")
cty=input("Enter City : ")
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()

sql="INSERT INTO student(sname,admno,dob,cls,cty) VALUES ( '%s'


,'%d','%s','%s','%s')"%(sname,admno,dob,cls,cty)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()
#insert()

def display1():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM student"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
sname = c[0]
admno= c[1]
dob=c[2]
cls=c[3]
cty=c[4]
print ("(sname=%s,admno=%d,dob=%s,cls=%s,cty=%s)" % (sname,admno,dob,cls,cty))
except:
print ("Error: unable to fetch data")
db.close()
def update1():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM student"
cursor.execute(sql)
results = cursor.fetchall()

for c in results:
sname = c[0]
admno= c[1]
dob=c[2]
cls=c[3]
cty=c[4]
except:
print ("Error: unable to fetch data")
print()
tempst=int(input("Enter Admission No : "))
temp=input("Enter new class : ")
try:
sql = "Update student set cls=%s where admno='%d'" % (temp,tempst)
cursor.execute(sql)
db.commit()
except Exception as e:
print (e)

db.close()
def delete1():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM student"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
sname = c[0]
admno= c[1]
dob=c[2]
cls=c[3]
cty=c[4]
except:
print ("Error: unable to fetch data")

temp=int(input("\nEnter adm no to be deleted : "))


try:
sql = "delete from student where admno='%d'" % (temp)
ans=input("Are you sure you want to delete the record(y/n) : ")
if ans=='y' or ans=='Y':
cursor.execute(sql)
db.commit()
except Exception as e:
print (e)
db.close()
def insert2():
ename=input("Enter Employee Name : ")
empno=int(input("Enter Employee No : "))
job=input("Enter Designation: ")
hiredate=input("Enter date of joining: ")
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql="INSERT INTO emp(ename,empno,job,hiredate) VALUES ( '%s'
,'%d','%s','%s')"%(ename,empno,job,hiredate)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()
def display2():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM emp"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
ename = c[0]
empno= c[1]

job=c[2]
hiredate=c[3]
print ("(empno=%d,ename=%s,job=%s,hiredate=%s)" % (empno,ename,job,hiredate))
except:
print ("Error: unable to fetch data")
db.close()
def update2():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM emp"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
ename = c[0]
empno= c[1]
job=c[2]
hiredate=c[3]
except:
print ("Error: unable to fetch data")
print()
tempst=int(input("Enter Employee No : "))
temp=input("Enter new designation : ")
try:
sql = "Update emp set job=%s where empno='%d'" % (temp,tempst)
cursor.execute(sql)
db.commit()
except Exception as e:
print (e)
db.close()
def delete2():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM emp"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
ename = c[0]
empno= c[1]
job=c[2]
hiredate=c[3]
except:
print ("Error: unable to fetch data")

temp=int(input("\nEnter emp no to be deleted : "))


try:
sql = "delete from emp where empno='%d'" % (temp)
ans=input("Are you sure you want to delete the record(y/n) : ")
if ans=='y'or ans=='Y':
cursor.execute(sql)

db.commit()
except Exception as e:
print (e)
db.close()
def insert3():
admno=int(input("Enter adm no: "))
fee=float(input("Enter fee amount : "))
month=input("Enter Month: ")
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql="INSERT INTO fee(admno,fee,month) VALUES ( '%d','%d','%s')"%(admno,fee,month)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()

def display3():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM fee"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
admno= c[0]
fee=c[1]
month=c[2]
print ("(admno=%d,fee=%s,month=%s)" % (admno,fee,month))
except:
print ("Error: unable to fetch data")
db.close()
def update3():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM fee"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
admno= c[0]
fee=c[1]
month=c[2]
except:
print ("Error: unable to fetch data")
print()
tempst=int(input("Enter Admission No : "))
temp=input("Enter new class : ")
try:
sql = "Update fee set month=%s where admno='%d'" % (temp,tempst)
cursor.execute(sql)

db.commit()
except Exception as e:
print (e)
db.close()
def delete3():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM fee"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
admno= c[0]
fee=c[1]
month=c[2]
except:
print ("Error: unable to fetch data")
temp=int(input("Enter adm no to be deleted : "))
try:
sql = "delete from student where admno='%d'" % (temp)
ans=input("Are you sure you want to delete the record(y/n) : ")
if ans=='y' or ans=='Y':
cursor.execute(sql)
db.commit()
except Exception as e:
print (e)
db.close()
def insert4():
sname=input("Enter Student Name : ")
admno=int(input("Enter Admission No : "))
per=float(input("Enter percentage : "))
res=input("Enter result: ")
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql="INSERT INTO exam(sname,admno,per,res) VALUES ( '%s'
,'%d','%s','%s')"%(sname,admno,per,res)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()
def display4():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM exam"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
sname = c[0]
admno= c[1]
dob=c[2]
cls=c[3]
cty=c[4]
print ("(sname,admno,per,res)"%(sname,admno,per,res) )
except:
print ("Error: unable to fetch data")
db.close()

def update4():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM exam"
cursor.execute(sql)
results = cursor.fetchall()

for c in results:
sname = c[0]
admno= c[1]
dob=c[2]
cls=c[3]
cty=c[4]
except:
print ("Error: unable to fetch data")
print()
tempst=int(input("Enter Admission No : "))
temp=input("Enter new result : ")
try:
sql = "Update student set res=%s where admno='%d'" % (temp,tempst)
cursor.execute(sql)
db.commit()
except Exceptionn as e:
print (e)
db.close()
def delete4():
try:
db = mysql.connector.connect(user='root', password='Gau2002',
host='localhost',database='mysql')
cursor = db.cursor()
sql = "SELECT * FROM exam"
cursor.execute(sql)
results = cursor.fetchall()
for c in results:
sname = c[0]
admno= c[1]
dob=c[2]
cls=c[3]
cty=c[4]
except:
print ("Error: unable to fetch data")

temp=int(input("\nEnter adm no to be deleted : "))


try:
sql ="delete from exam where admno=%d"% (temp)
ans=input("Are you sure you want to delete the record(y/n): ")
if ans=='y' or ans=='Y':
cursor.execute(sql)
db.commit()
except Exception as e:
print (e)
db.close()
selection()
OUTPUT:

INSERT DETAILS

File Edit Shell Debug Options Window Help


Python 3.6.5 (v3.6.5:f59c0932b9, Har 28 2018, 16:07:H) (HSC v.1900 32 bit (Inte •
l)J on win32
Type "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: D:\pythonEXE\DBconnectivity.py ==================
WELCOHE TO SCHOOL HANAGEHENT SYSTEH

!.STUDENT HANAGEHENT
2.EHPLOYEE HANAGEHENT
3.FEE HANAGEHENT
4.EXAH HANAGEHENT

Enter ur choice (1-4) : 1

WELCOHE TO STUDENT HANAGEHENT SYSTEH

a.NEW ADHISSION
b.UPDATE STUDENT DETAILS
c.ISSUE TC
Enter ur choice (a-c) : a

Initially the details are..

(sname=Reema,admno=2089,dob=1111-11-11,cls=S,cty=Delhi)
(sname=Jitu,adro
r=2341,dob=2012-01-01,cls=2,cty=Sehore)
(sname=qwerty,adro
r =3456,dob=3333-33-33,cls=3,cty=fghj)
Enter Student Name : Deepak Kumar
Enter Admission No : 2114
Enter Date of Birth(yyyy-rom-dd: 2012-11-07
Enter class for admission: 1
Enter City : Indore

Hodi fied deta ils are . .

(sname=Reema,admno=2089,dob=1111-11-11,cls=S,cty=Delhi)
(sname=Deepak Kumar,admno=2114rdob=2012-11-07,cls=1,cty=Indore)
(sname=Jitu,adro
r=2341,dob=2012-01-01,cls=2,cty=Sehore)
(sname=qwerty,adro
r =3456,dob=3333-33-33,cls=3,cty=fghj)
>>>
UPDATE DETAILS

t} Python 3.6.5 Shell l = [&l tt 'I


File Edit Shell Debug Option; Window Help
Python 3 .6.5 (v3 .6.5:f59c0932b'!!, Har 2 8 2 018, 16:07 :4 6) (HSC v .1900 32 bit (Inte •
l)J on win32
Type "copyright", "credits" or "license()" for more information.
>>>
================== RESTART : D:/pythonEXE/DBconnectivtiy. py ==================
WELCOHE TO SCHOOL !1ANAGE!1ENT SYSTEH

1.STUDENT !1ANAGE!1ENT
2.E1 l PLOYEE l-IANAGEHENT
3 .FEE HANAGEHENT
4 • EXAH l-IANAGEHENT

Enter ur choice (1-4) : 1

WELCOHE TO STUDENT !1ANAGE!1ENT SYSTEH

a . NEW ADHISSION
b. UPDATE STUDENT DETAILS
c.ISSUE TC
Enter ur choice (a-c) : b

Initially the details are..

(snaroe=Reema,a ,o=2089,dob=1111-11-
11,cls=3,cty=Delhi) (sname=nerty,a ,o=3456,dob=3333-
33-33,cls=3,cty=fghj)

Enter Adwissicn No : 2089


Enter new class : 5

Hodi f ied details a re . .

(sname=Reema,a ,o=2089,dob=1111-11-
11,cls=5,cty=Delhi) (sname=nerty,a ,o=3456,dob=3333-
33-33,cls=3,cty=fghj)
>>>
DELETE DETAILS

1} Python 3.6.5 Shell


File Edit Shell Debug Options W.ndo.. Help
Pychon 3.6.5 (v3.6.5:f59c0932b , Mar 28 2018, 16:07:'!6) (MSC v.1900 32 bic
(Ince l)) on win32
Type "copyriQht.", "credit.s" or "license()" tor more informacion.
>>>

•••••••••••••••••RESTART: O:/pyehon£XE/0Bconneccivicy.py ••••••••••••••••••

WELCOME TO SCHOOL MANAGEMENT SYSTEM

l.STUDENT MANAGEMENT
2.E!1PLOYEE MANAGEMENT
3.FEE MANAGEMENT
4.EXAM MANAGEMENT

Encr ur choic (1-4) : l

WELCOME TO STUDENT MANAGEMENT SYSTEM

a.NEW ADMISSION
b.UPDATE STUDENT DETAILS
c.ISSUE TC
Encr ur choic (a-c) : c

Inicially chdeeails ar..

(snarn ·ad,adrnno•ll,dob-1111-11-ll,cls•12,ccy-we)
(snarn •Re ma,adrnno•2089,dob-1111-11-ll,cls•3,ccy-Delh1)
(snarn ·qw rcy,adrnno•3456,dob-3333-33-33,cls•3,ccy-tqhj)

Encr adm no co be delec d : 11


Are you sure you wane co delece ehr cord(y/n) y

Mod1t1d d eails are..

(snarr.·R ma.adrnno•2089,dob-llll-ll-11,cls•3,cey•Delhi)
(snarn ·qw rey,admoo•3456,dob-3333-33-33,cls•3,cey•tqhj)
>>>
Bibliography

1. www.google.com

2. www.wikipedia.in

3. Computer Science with

python by SUMITA ARORA

You might also like