SET 1
1. a. Write a menu drive program to perform following operations into a binary file
“shoespoint.dat”.
i. Add record ii. Display records iii. Search record iv. Exit
The structure of file content is: [s_id, name, brand, type, and price]
import pickle
def add():
with open("shoespoint.dat", "ab") as f:
s_id = int(input("Enter Shoe ID: "))
name = input("Enter Shoe Name: ")
brand = input("Enter Brand: ")
stype = input("Enter Type: ")
price = float(input("Enter Price: "))
record = [s_id, name, brand, stype, price]
pickle.dump(record, f)
def display():
with open("shoespoint.dat", "rb") as f:
try:
while True:
record = pickle.load(f)
print(record)
except:
pass
def search():
s_id = int(input("Enter Shoe ID to search: "))
found = False
with open("shoespoint.dat", "rb") as f:
try:
while True:
record = pickle.load(f)
if record[0] == s_id:
print("Record Found:", record)
found = True
if found == False:
print('No Data found.')
except:
pass
while True:
print("Menu:")
print("1. Add Record")
print("2. Display Records")
print("3. Search Record")
print("4. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
add()
elif ch == 2:
display()
elif ch == 3:
search()
else:
break
b. Consider the personal and job table and write SQL commands for given statements:
Table: Personal
Empno Name Dobirth Native_place Hobby
123 Amit 23/01/1965 Delhi Music
127 Manoj 12/12/1976 Mumbai Writing
124 Abhai 11/08/1975 Allahabad Music
125 Vinod 04/04/1977 Delhi Sports
128 Abhay 10/03/1974 Mumbai Gardening
129 Ramesh 28/10-1981 Pune Sports
Table: Job
Sno Area App_date Salary Retd_date Dept.
123 Agra 25/01/2006 5000 25/01/2026 Marketing
127 Mathura 22/12/2006 6000 22/12/2026 Finance
124 Agra 19/08/2007 5500 19/08/2027 Marketing
125 Delhi 14/04/2004 8500 14/04/2018 Sales
128 Pune 13/03/2008 7500 13/03/2028 Sales
129 Bangalore 21/07/2003 7000 21/07/2023 Finance
Write SQL queries for the following:
a) Show Empno, Name and Salary of those who have Sports as hobby.
SELECT P.Empno, P.Name, J.Salary
FROM Personal P, Job J
WHERE P.Empno = J.Sno AND P.Hobby = 'Sports';
b) Show Sno, Name, Hobby and Salary in descending order of Salary.
SELECT J.Sno, P.Name, P.Hobby, J.Salary
FROM Personal P, Job J
WHERE P.Empno = J.Sno
ORDER BY J.Salary DESC;
c) Show the appointment date and native place of those whose name starts with 'A' or
ends in‘d’.
SELECT J.App_date, P.Native_place
FROM Personal P, Job J
WHERE P.Empno = J.Sno
AND (P.Name LIKE 'A%' OR P.Name LIKE '%d');
d) Show the hobby of which there are 2 or more employees.
SELECT Hobby
FROM PERSONAL
GROUP BY Hobby
HAVING COUNT(*) >= 2;
SET 2
1. a. Write a menu drive program to perform following operations into a CSV file 8
“Emplyoee.csv”.
i. Update record ii. Display records iii. Search record iv. Exit
The structure of file content is: [Empid, Name, Mobileno]
import csv
def update():
empid = input("Enter Employee ID to update: ")
records = []
updated = False
with open("Employee.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
if row[0] == empid:
name = input("Enter New Name: ")
mobileno = input("Enter New Mobile No: ")
records.append([empid, name, mobileno])
updated = True
else:
records.append(row)
if updated == False:
print('No Employee is found')
return
with open("Employee.csv", "w", newline='') as f:
writer = csv.writer(f)
writer.writerows(records)
print('Updated successfully')
def display():
try:
with open("Employee.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
print(row)
except:
pass
def search():
empid = input("Enter Employee ID to search: ")
with open("Employee.csv", "r") as f:
found = False
reader = csv.reader(f)
for row in reader:
if row[0] == empid:
print("Record Found:", row)
found = True
if found == False:
print('No Data found.')
while True:
print("Menu:")
print("1. Update Record")
print("2. Display Records")
print("3. Search Record")
print("4. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
update()
elif ch == 2:
display()
elif ch == 3:
search()
else:
break
b. Consider the tables books and issue write SQL command for given statements: 4
i. Display the unique book types from the book table.
SELECT DISTINCT TYPE FROM BOOKS;
ii. Increase the price of all computer books by 70.
UPDATE BOOKS
SET PRICE = PRICE + 70
WHERE TYPE = 'COMPUTER';
iii. Display the book id, book name and quantity issued for all books which have been issued.
SELECT B.BID, B.BNAME, I.QTY_ISSUED
FROM BOOKS B , ISSUED I
WHERE B.BID = I.BID;
iv. Display the book id, book name, author name for all books which price is 200 to 400.
SELECT BID, BNAME, AUNAME
FROM BOOKS
WHERE PRICE BETWEEN 200 AND 400;
SET 3
1. a. Write a Python program to create Lpush( ) and Lpop( ) function to do push and pop 8
operation on a stack using a list e.g. take a student information and push and pop the
details
def isEmpty(S):
if len(S) == 0:
return True
else:
return False
def Push(S,item):
S.append(item)
def Pop(S):
if isEmpty(S):
return "Underflow"
else:
item = S.pop()
return item
s=[]
while True:
print("*****STACK DEMONSTRATION*****")
print("1. PUSH")
print("2. POP")
print("0. EXIT")
ch = int(input("Enter your Choice: "))
if ch == 1:
val = int(input("Enter the item to Push: "))
Push(s,val)
elif ch == 2:
val = Pop(s)
if val == "Underflow":
print("Stack is Empty")
else:
print("Popped Item is:",val)
elif ch == 0:
print("THANK YOU")
break
b. Write a python program to integrate SQL with python by importing the MySql module record of
employee and display the record.
import mysql.connector as m
con = m.connect(user = 'root', host = 'localhost', passwd =
'snvv@2018', database = 'EMPDB', charset = 'utf8')
cur = con.cursor()
cur.execute('select * from employee')
for x in cur:
print(x)