Set 1
Set 1
Q-1 a) Write a menu driven program to perform following operations into a binary
fileshoes.dat.
1.Add record
2.Display records
3.Search record
4.Exit
The structure of file content is: [s_id, name, brand, type, price]
SOURCE CODE:
import pickle
l=[]
found=0
def add_rec():
f=open("shoes.dat","ab")
s_id=int(input("Enter Shoes ID:"))
name=input("Enter Name:")
brand=input("Enter Brand:")
type=input("Enter Type:")
price=int(input("Enter Price:"))
l=[s_id,name,brand,type,price]
pickle.dump(l,f)
print("Record Added.")
f.close()
def dis_rec():
f=open("shoes.dat","rb")
while True:
try:
l=pickle.load(f)
print(l)
except EOFError:
f.close()
break
def search_record():
f=open("shoes.dat","rb")
s_id=int(input("Enter Shoe ID:"))
while True:
try:
l=pickle.load(f)
if l[0]==s_id:
found=1
print("Record Found:",l)
else:
found=0
except EOFError:
f.close()
break
if found==0:
print("Record Not Found!")
while True:
print('''
1. Add Record
2. Display Record
3. Search Record
4. Exit
''')
ch=int(input("Enter your choice:"))
if ch==1:
add_rec()
elif ch==2:
dis_rec()
elif ch==3:
search_record()
elif ch==4:
break
else:
print("Invalid Choice!")
OUTPUT:
Q-1 b) Write SQL command and output for the following queries using the
Relation- STU(4)
mysql> CREATE DATABASE SCHOOL;
Query OK, 1 row affected (0.20 sec)
a)
mysql> SELECT Name FROM STU WHERE Name LIKE '_n%';
+-------+
| Name |
+-------+
| Ankit |
| Anu |
+-------+
2 rows in set (0.00 sec)
b)
mysql> DELETE FROM STU WHERE Rollno = 8;
Query OK, 1 row affected (0.10 sec)
c)
mysql> ALTER TABLE STU ADD(Area varchar(15));
Query OK, 0 rows affected (0.29 sec)
Records: 0 Duplicates: 0 Warnings: 0