You are on page 1of 2

SET-4

1)

Create a CSV file by entering user-id and password, read and search the password
for given user id.

import csv
#user -id and password list
List=[["user1", "password1"],
["user2", "password2"],
["user3", "password3"],
["user4", "password4"],
["user5", "password5"]]
#opening the file to write the records
f1=open("userInformation.csv","w",newline="\n")
# Here, you create a CSV writer object called writer associated with the file f1.
writer=csv.writer(f1)
writer.writerows(List)
f1.close()
#opening the file to read the records
f2=open("userInformation.csv","r")
rows=csv.reader(f2)
userId=input("Enter the user-id:" )
flag = True
for record in rows:
if record[0]== userId:
print("The password is:",record[1])
flag= False
break
if flag:
print("User-id not found")

2)
Write a SQL queries for (i) to (iv) 4 marks.
Table: Salary
Fname Lname Income
John Smith 30000
Franklin Wong 40000
joyce English 80000
Ramesh Narayan 3800
James Borg 55000
Jennifer Wallance 43000
Ahmad jabbar 25000
Alicia Zeala 25000

create database lulu;

use lulu;

create table salary(Fname varchar(30),Lname varchar(30),Income varchar(30));

insert into salary value('John','Smith',30000);


insert into salary value('Franklin','Wong',40000);

insert into salary value('Joyce','English',80000);

insert into salary value('Ramesh','Narayan',3800);

insert into salary value('James','Borg',55000);

insert into salary value('Jennifer','Wallance',43000);

insert into salary value('Ahmad','Jabbar',25000);

insert into salary value('Alicia','Zeala',25000);

i. Write a Sql Query to display the Average salary paid.


select avg(income) from salary;

ii. Write a Sql Query to display whose income is more than 20000.
select Fname from salary where income>20000;

iii. Write a Sql Query to display the Fname in ascending order.


select * from salary order by Fname desc;

iv. Write a Sql Query to delete whose Lname is Smith.


delete from salary where Lname ='Smith';

You might also like