-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab16.py
More file actions
45 lines (44 loc) · 1.1 KB
/
Copy pathlab16.py
File metadata and controls
45 lines (44 loc) · 1.1 KB
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
#python program to demonstrate database using sqlite3
import sqlite3 as sql
con=sql.connect("example.db")
cur=con.cursor()
sql="""
create table if not exists student
(
rno varchar(10),
name varchar(10),
primary key(rno)
)
"""
cur.executescript(sql)
con.commit
print("Table Created")
for i in range(1,6):
rno=input(f"Enter roll no of {i} student")
name=input(f"Enter name {i} student")
cur.execute("insert into student(rno,name) values(?,?)",(rno,name))
con.commit()
print("data Inserted")
def display():
global cur
cur.execute("select * from student")
rows=cur.fetchall()
print("Student data as follows")
print("Rollno\t|Name\t|")
for row in rows:
rno=row[0]
name=row[1]
print(f"{rno}\t|{name}\t|")
display()
rno=input("Enter the roll no you want to update")
name=input("Enter the correct name")
cur.execute("update student set name=? where rno=?",(name,rno))
con.commit()
print("data updated")
display()
rno=input("enter the roll no you want to delete")
cur.execute("delete from student where rno=?",(rno,))
con.commit()
print("data deleted")
display()
con.close()