0% found this document useful (0 votes)
11 views6 pages

Projectcsxiis 1

This Python program defines functions to interact with a school database to view, update, add, and delete student profiles and academic performance records. The program displays menus to allow the user to select different functions like displaying individual or collective student results, viewing or updating profile details, adding new student records, or deleting a student record based on an admission number. It connects to a MySQL database called 'school' and uses SQL queries and commands to fetch, manipulate and commit data from various tables like 'admission', 'science', 'humanities', 'commerce' etc.

Uploaded by

Raman Singh
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)
11 views6 pages

Projectcsxiis 1

This Python program defines functions to interact with a school database to view, update, add, and delete student profiles and academic performance records. The program displays menus to allow the user to select different functions like displaying individual or collective student results, viewing or updating profile details, adding new student records, or deleting a student record based on an admission number. It connects to a MySQL database called 'school' and uses SQL queries and commands to fetch, manipulate and commit data from various tables like 'admission', 'science', 'humanities', 'commerce' etc.

Uploaded by

Raman Singh
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/ 6

import mysql.

connector as py
con=py.connect(host="localhost",user="root",password="tiger",database="school")
c=con.cursor()
def collect_perf():
count=0
ad=int(input("Enter Admission number:"))
stream=input("Enter your stream(Science/Commerce/Humanities:")
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad and i[9].upper()==stream.upper():
print("Successfully login!")
count+=1
if count==0:
print("Admission Number or Stream is invalid!")
else:
if stream.upper()=="SCIENCE":
c.execute("Select * from science")
data=c.fetchall()
print(" Ad_No Name \t Physics\tChem\tMaths\tCS\tEng\tPercent")
for i in data:
print(i[0]," ",i[1]," ",i[2],"
",i[3],"\t",i[4],"\t",i[5],"\t",i[6],"\t",i[7])
elif stream.upper()=="HUMANITIES":
c.execute("Select * from humanities")
data=c.fetchall()
print(" Ad_No Name \t History\tPolSci\tIP\tHindi Eng\tPercent")
for i in data:
print(i[0]," ",i[1]," ",i[2],"
",i[3],"\t",i[4],"\t",i[5],"\t",i[6],"\t",i[7])
elif stream.upper()=="COMMERCE":
c.execute("Select * from commerce")
data=c.fetchall()
print(" Ad_No Name \t Accounts\tBST\tEco \tIP\t Eng\tPercent")
for i in data:
print(i[0]," ",i[1]," ",i[2],"
",i[3],"\t",i[4],"\t",i[5],"\t",i[6],"\t",i[7])

def ind_perf():
count=0
ad=int(input("Enter Admission number:"))
stream=input("Enter your stream(Science/Commerce/Humanities):")
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad and i[9].upper()==stream.upper():
print("Successfully login!")
count+=1
if count==0:
print("Admission Number or Stream is invalid!")
else:
if stream.upper()=="SCIENCE":
c.execute("Select * from science where Ad_No={}".format(ad))
data=c.fetchall()
print(" Ad_No Name \t Physics\tChem\tMaths\tCS\tEng\tPercent")
for i in data:
print(i[0]," ",i[1]," ",i[2],"
",i[3],"\t",i[4],"\t",i[5],"\t",i[6],"\t",i[7])
elif stream.upper()=="HUMANITIES":
c.execute("Select * from humanities where Ad_No={}".format(ad))
data=c.fetchall()
print(" Ad_No Name \t History\tPolSci IP\tHindi Eng\tPercent")
for i in data:
print(i[0]," ",i[1]," ",i[2],"
",i[3],"\t",i[4],"\t",i[5],"\t",i[6],"\t",i[7])
elif stream.upper()=="COMMERCE":
c.execute("Select * from commerce where Ad_No={}".format(ad))
data=c.fetchall()
print(" Ad_No Name \t Accounts\tBST\tEco \tIP\t Eng\tPercent")
for i in data:
print(i[0]," ",i[1]," ",i[2],"
",i[3],"\t",i[4],"\t",i[5],"\t",i[6],"\t",i[7])
def profile():
count=0
ad=int(input("Enter Admission number:"))
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad and i:
print("Successfully login!")
count+=1
if count==0:
print("Admission Number is invalid!")
else:
c.execute("Select * from admission where Ad_No={}".format(ad))
data=c.fetchall()
for i in data:
print("""Admission_No:""",i[0],"""| Name:""",i[1],
"""\nFather's Name:""",i[2],"""| Mother's Name:""",i[3],
"""\nEnrollment Date:""",i[4],"""| Date Of Birth:""",i[5],
"""\nAddress:""",i[6],
"""\nMobile Number:""",i[7],"""| Gender:""",i[8],
"""\nStream:""",i[9])

def up_name():
count=0
ad=int(input("Enter Admission number:"))
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad :
print("Successfully login!")
print("Name:",i[1])
count+=1
if count==0:
print("Admission Number is invalid!")
else:
name=input("Enter new name:")
q="update admission set Name='{}' where Ad_No={}"
c.execute(q.format(name,ad))
con.commit()
print("Successfully changed!")
def up_address():
count=0
ad=int(input("Enter Admission number:"))
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad :
print("Successfully login!")
print("Address:",i[6])
count+=1
if count==0:
print("Admission Number is invalid!")
else:
name=input("Enter new address:")
q="update admission set Address='{}' where Ad_No={}"
c.execute(q.format(name,ad))
con.commit()
print("Successfully changed!")
def up_phone():
count=0
ad=int(input("Enter Admission number:"))
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad :
print("Successfully login!")
print("Phone:",i[7])
count+=1
if count==0:
print("Admission Number is invalid!")
else:
name=int(input("Enter new Phone Number:"))
q="update admission set Phone_No={} where Ad_No={}"
c.execute(q.format(name,ad))
con.commit()
print("Successfully changed!")
def up_fees():
count=0
ad=int(input("Enter Admission number:"))
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad :
print("Successfully login!")
count+=1
if count==0:
print("Admission Number is invalid!")
else:
c.execute("Select * from fees")
data=c.fetchall()
for i in data:
if i[0]==ad and i[4]=="No":
print("No Dues! Fees are already paid!")
elif i[0]==ad and i[4]=="Yes":
print("Due Amount:",i[5])
print("Bank Account:",i[3])
pay=input("Pay from Bank Account(yes/no):")
if pay.upper()=="YES":
amt=0
q="update fees set Due_amount={},Due='{}' where Ad_No={}"
c.execute(q.format(amt,"No",ad))
con.commit()
print("Successfully changed!")
def add():
a=input("Enter Student Name:")
b=input("Enter Father Name:")
cc=input("Enter Mother Name:")
d=input("Enter DOB:")
e=input("Address:")
f=int(input("Mobile Number:"))
g=input("Gender(M/F):")
h=input("Stream:")
i=input("Mode of payment:")
j=int(input("Bank Account:"))
c.execute("select max(Ad_No) from admission")
ad_no=c.fetchall()
for new in ad_no:
num=new[0]
num+=1
print("Your Admission Number is :",num)
admission="insert into admission values (
{},'{}','{}','{}',curdate(),'{}','{}',{},'{}','{}')"
c.execute(admission.format(num,a,b,cc,d,e,f,g,h))
con.commit()
fees="insert into fees values ( {},'{}','{}',{},'{}',{})"
c.execute(fees.format(num,a,i,j,"Yes",7500))
con.commit()
if h=="Science":
c.execute("insert into science(Ad_No,Name) values ({},'{}')".format(num,a))
con.commit()
elif h=="Humanities":
c.execute("insert into humanities(Ad_No,Name) values
({},'{}')".format(num,a))
con.commit()
elif h=="Commerce":
c.execute("insert into commerce(Ad_No,Name) values
({},'{}')".format(num,a))
con.commit()
print("Record added!")
def delete_():
count=0
ad=int(input("Enter Admission number:"))
c.execute("Select * from admission")
data=c.fetchall()
for i in data:
if i[0]==ad :
print("Successfully login!")
count+=1
if count==0:
print("Admission Number or Stream is invalid!")
else:
c.execute("Delete from admission where Ad_No={}".format(ad))
con.commit()
print("Successfully deleted!")
try:
print("Welcome to Ramay International School")
while True:

print('''
1. Display Details
2. Update Details
3. Add Details
4. Delete Details
5. Exit''')
ch=int(input("Enter your Preference:"))
if ch==1:
print('''Select your Choice:
1. Academic Performance
2. Student Profile''')
a=int(input("Enter your choice:"))
if a==1:
print('''Select your Preference:
1. Individual Performance
2. Collective Performance''')
b=int(input("Enter your priority:"))
if b==1:
ind_perf()
elif b==2:
collect_perf()
elif a==2:
profile()
else:
print("Invalid action!")
elif ch==2:
print("""Choose the Field you want to update-
1. Name
2. Address
3. Mobile Number
4. Fees""")
ch=int(input("Enter your Preference:"))
if ch==1:
up_name()
elif ch==2:
up_address()
elif ch==3:
up_phone()
elif ch==4:
up_fees()
else:
print("Invalid action")
elif ch==3:
add()
elif ch==4:
delete_()
else:
print("Thankyou for being part of this School")
break

except ValueError:
print("Please Write/choose a correct option")

You might also like