sdbm mbs.py

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

while(True):

print('1.insert')
print('2.Search specific')
print('3.Display')
print('4.Update')
print('5.Delete')
print('6.Graph')
print('7.Exit')
ch=int(input('Enter your choice:'))
if(ch==1):
import pymysql

conn=pymysql.connect(host='localhost',user='root',password='manager',database='proj
ect')
a=conn.cursor()
r=int(input('Enter roll number:'))
nm=input('Enter Name:')
m=float(input('Enter marks:'))
s='insert into student values('+str(r)+',"'+nm+'",'+str(m)+')'
a.execute(s)
print('one row inserted successfully:')
conn.commit()
elif(ch==2):
import pymysql

conn=pymysql.connect(host='localhost',user='root',password='manager',database='proj
ect')
a=conn.cursor()
r=int(input('Enter roll number of student to search'))
s='select *from student where rno='+str(r)
a.execute(s)
data=a.fetchall()
if(len(data)==0):
print('Student roll number',r,'doesnot exists')
else:
print('Student roll number=',r)
print('Student Name=',data[0][1])
print('Student marks=',data[0][2])
conn.commit()
elif(ch==3):
import pymysql

conn=pymysql.connect(host='localhost',user='root',password='manager',database='proj
ect')
a=conn.cursor()
s='select *from student'
a.execute(s)
data=a.fetchall()
for i in data:
for j in i:
print(j,end=' ')
print()
conn.commit()
elif(ch==4):
import pymysql

conn=pymysql.connect(host='localhost',user='root',password='manager',database='proj
ect')
a=conn.cursor()
r=int(input('Enter roll number of student to update'))
s='select *from student where rno='+str(r)
a.execute(s)
data=a.fetchall()
if(len(data)==0):
print('Student roll number',r,'doesnot exists')
else:
print('Exiting details:')
print('Student roll number=',r)
print('Student Name=',data[0][1])
print('Student marks=',data[0][2])
nn=input('Enter new name:')
nm=float(input('Enter new marks:'))
s='update student set name="'+nn+'", marks='+str(nm)+' where
rno='+str(r)
a.execute(s)
print('updated successfully:')
conn.commit()
elif(ch==5):
import pymysql

conn=pymysql.connect(host='localhost',user='root',password='manager',database='proj
ect')
a=conn.cursor()
r=int(input('Enter roll number of student to delete:'))
s='select *from student where rno='+str(r)
a.execute(s)
data=a.fetchall()
if(len(data)==0):
print('Student roll number',r,'doesnot exists')
else:
s='delete from student where rno='+str(r)
a.execute(s)
print('deleted successfully:')
conn.commit()
elif(ch==6):
import pymysql
import matplotlib.pyplot as plt

conn=pymysql.connect(host='localhost',user='root',password='manager',database='proj
ect')
a=conn.cursor()
s='select *from student'
a.execute(s)
data=a.fetchall()
L1=[]
L2=[]
for i in data:
L1.append(i[1])
L2.append(int(i[2]))

plt.bar(L1,L2)
plt.xlabel('Student name')
plt.ylabel('Student Marks')
plt.title('Student progress card')

plt.show()
conn.commit()
elif(ch==7):
break
else:
print('Invalid choice...please enter choice in between 1 to 7')

You might also like