-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
39 lines (37 loc) · 1.19 KB
/
db.py
File metadata and controls
39 lines (37 loc) · 1.19 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
#dbms with python
import sqlite3
connection=sqlite3.connect('sample.db')
cursor=connection.cursor()
print("connected")
def createTable(query):
cursor.execute(query)
print("created")
def insert():
name=input("enter the student name: ")
age=int(input("enter age: "))
mark=int(input("enter the mark: "))
cursor.execute("Insert into studentdb4 values(?,?,?)",(name,age,mark))
print("inserted successfully")
def update():
name=input("enter the student name: ")
mark=int(input("enter the mark: "))
cursor.execute("update studentdb4 SET mark= ? WHERE name=?",(mark,name))
print("updated successfully")
def display():
row=cursor.execute("select * from studentdb4").fetchall()
print(row)
query="CREATE TABLE studentdb4(name text,age integer,mark integer)"
createTable(query)
print("Enter the operation to be performed: 1.insert 2.update 3.display 4.exit")
choice=int(input())
while(choice!=4):
if(choice==1):
insert()
elif(choice==2):
update()
elif(choice==3):
display()
else:
print("recheck the choice entered")
print("Enter the operation to be performed: 1.insert 2.update 3.display 4.exit")
choice=int(input())