-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathprogram to update books record in library.py
62 lines (58 loc) · 1.7 KB
/
program to update books record in library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import mysql.connector
con=mysql.connector.connect(host='localhost',password='Sachin2002',user='root',database='mysql')
cur=con.cursor()
def input_record():
while True:
no=int(input("Book No :"))
nm=input("Enter Book name :")
p=int(input("Enter Price :"))
query= ''' INSERT INTO CompSci
VALUES({},"{}",{})'''.format(no,nm,p)
cur.execute(query)
con.commit()
ch=input("You want to continue?(y/n)")
if ch=="n":
break
def update_price():
no=int(input("BOOK NO :"))
p=int(input("Enter Price :"))
sql=""" UPDATE CompSci
SET Price={}
WHERE bookno={}""".format(p,no)
cur.execute(sql)
con.commit()
def show_record():
query="""SELECT *
FROM CompSci"""
cur.execute(query)
data=cur.fetchall()
for i in data:
print(i)
def delete_record():
no=int(input("BOOK NO :"))
query="""DELETE FROM CompSci
WHERE bookno={}""".format(no,)
cur.execute(query)
con.commit()
def menu():
print("1. Input Records")
print("2. Show Records")
print("3. Update Records")
print("4. Delete Records")
print("5. Exit")
ch=int(input("Enter Your Choice from 1 to 5 :"))
if ch==1:
input_record()
return menu()
if ch==2:
show_record()
return menu()
if ch==3:
update_price()
return menu()
if ch==4:
delete_record()
return menu()
else:
print("Thank You For Choosing our System.....")
menu()