-
Notifications
You must be signed in to change notification settings - Fork 0
/
Experiment 11 (c)
91 lines (67 loc) · 2.24 KB
/
Experiment 11 (c)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import sqlite3
con=sqlite3.connect("mydb.db")
con.execute(
'''
create table products
(
productid int,
productname text,
price float
)
'''
)
print("Table created successfully!!!")
def menu():
print("======MENU=======")
print("1. Add Product")
print("2. Delete Product")
print("3. Update Product")
print("4. Display Products")
ch=int(input("Select one option:"))
if(ch==1):
def insert():
import sqlite3
productid=int(input("Enter product id:"))
productnm=input("Enter product name:")
productpr=float(input("Enter product price:"))
con=sqlite3.connect("mydb.db")
con.execute("insert into products values(?,?,?)",(productid,productnm,productpr))
con.commit()
print("Product Inserted successfully!!!")
insert()
elif(ch==2):
def delete():
import sqlite3
productid=int(input("Enter product id:"))
con=sqlite3.connect("mydb.db")
con.execute("delete from products where productid=?",(productid,))
con.commit()
print("Product deleted successfully!!!")
delete()
elif(ch==3):
def update():
import sqlite3
productid=int(input("Enter productid:"))
productnm=input("Enter new product name:")
con=sqlite3.connect("mydb.db")
con.execute("update products set productname=? where productid=?",(productnm,productid))
con.commit()
print("Product updated successfully!!")
update()
elif(ch==4):
def select():
import sqlite3
con=sqlite3.connect("mydb.db")
rows=con.execute("select * from products")
for row in rows:
print("Product id: ",row[0])
print("Product name: ",row[1])
print("Product price: ",row[2])
print()
select()
else:
print("invalid option!!!")
ch=input("Do you want to continue with this app?").lower()
if(ch=="yes"):
menu()
menu()