Code2pdf 677232d7d76d7
Code2pdf 677232d7d76d7
connector as my
m=my.connect(host="localhost",user="root",passwd="SHLOK@2006#23",database="lps",charset="utf8")
######################################
def push():
cur=m.cursor()
n=input("Enter the student name")
r=int(input("Enter the student admission number."))
x=search_exist(r)
if x==1:
print("Sorry invalid ad_no")
return
a=input("Enter the student address")
st="insert into stu (s_name,ad_no,address) values('{}',{},'{}')".format(n,r,a)
cur.execute(st)
m.commit()
####################################
def search():
cur=m.cursor()
r=int(input("Enter the student addmission number."))
st="select * from stu where ad_no=%s" %(r,)
cur.execute(st)
da=cur.fetchall()
for r in da:
print(r)
####################################
def dele(p):
x=search_exist(p)
if x==0:
print("Sorry invalid ad_no")
return
cur=m.cursor()
st="delete from stu where ad_no=%s" %(p,)
cur.execute(st)
m.commit()
#############################################
def display():
cur=m.cursor()
st="select * from stu"
cur.execute(st)
da=cur.fetchall()
for j in da:
print(j)
####################################
####################################
def search_exist(r):
cur=m.cursor()
st="select ad_no from stu where ad_no=%s" %(r,)
cur.execute(st)
da=cur.fetchall()
for j in da:
if j[0]==r:
return 1
return 0
####################################
print("School Management System")
i=1
while i==1:
print("press 1 for enroll no.")
print("press 2 for search")
print("press 3 for delete")
print("press 4 for display records")
print("press 5 for exit")
x=int(input("Enter ur choice"))
if x==1:
push()
elif x==2:
search()
elif x==3:
d=int(input("Enter the left out roll no."))
dele(d)
elif x==4:
display()
elif x==5:
break
i=int(input("Do u want more press 0 for exit and 1 for exit"))
#################################