You are on page 1of 7

Assessment-5

JAI KUMAR TIWARI


18MCA0077

1. Write a python program to get a value from the user and check if it is having unique
values. If there are duplicate value throw an exception through print statement.
try:
string=input("Enter the string ")
length=len(string)
count=0
for i in range(length):
for j in range((i+1),length):
if(string[i]==string[j]):
count+=1
if(count>0):
raise()
else:
print("string is unique")
except Exception:
print("number of duplicate values : ",count)
2. Write a python program to create a database, and perform the following operations:
a) Create a table,
b) Insert values in the table,
c) Query a table,
d) Update a value in the table and
e) Delete a value in the table.
import sqlite3

conn=sqlite3.connect('assesment.db')

conn.execute('''CREATE TABLE student1(Roll_id INTEGER PRIMARY KEY,Name TEXT NOT NULL,Age


INTEGER NOT NULL,Python_marks NOT NULL);''')

conn.execute("INSERT INTO student1 VALUES(1,'jai',21,43);")

conn.execute("INSERT INTO student1 VALUES(2,'kumar',22,44);")

conn.execute("INSERT INTO student1 VALUES(3,'tiwari',23,39);")

conn.execute("INSERT INTO student1 VALUES(4,'chauhan',24,36);")

conn.execute("INSERT INTO student1 VALUES(5,'sharma',25,21);")

data=conn.execute("SELECT * FROM student1");

for row in data:

print("Roll_id: ",row[0])

print("Name: ",row[1])

print("Age: ",row[2])

print("Python marks: ",row[3])

conn.commit()

conn.close()
import sqlite3
conn=sqlite3.connect('assesment.db')
conn.execute("UPDATE student1 SET Roll_id= 111 WHERE Roll_id = 5")
data1=conn.execute("SELECT * FROM student1");
for row in data1:
print("Roll_id: ",row[0])
print("Name: ",row[1])
print("Age: ",row[2])
print("Python marks: ",row[3])
conn.commit()
conn.close()
Updated value circled and highlighted
import sqlite3
conn=sqlite3.connect('assesment.db')
conn.execute("DELETE FROM student1 WHERE Roll_id = 111;")
data1=conn.execute("SELECT * FROM student1");
for row in data1:
print("Roll_id: ",row[0])
print("Name: ",row[1])
print("Age: ",row[2])
print("Python marks: ",row[3])
conn.commit()
conn.close()

You might also like