You are on page 1of 2

Sample paper solution

Ans 1

import pickle
def write_record():
rec=[]
f=open("emp.dat","wb")
ch='y'

while(ch=='y'):
en=int(input("Emp No "))
name1=input("Name")
address=input("Address ")
salary=int(input("Salary "))
L=[en,name1,address,salary]
rec.append(L)

ch=input("continue y/n ")


if ch=='n':
break
print(rec)
pickle.dump(rec,f)
f.close()

def read_record():
f=open("emp.dat","rb")
rec=pickle.load(f)
for i in rec:
if i[3]>=30000 and i[3]<=40000:
print(i[0],i[1],i[2],i[3])
#f.close()

ch2=1
while(ch2 !=3):
print(" Binary File Operation ")
print(" 1 - Write Records \n 2- Display salary(30000-40000 \n 3- exit")
ch2=int(input("choice 1-3 "))
if ch2==1:
write_record()
if ch2==2:
read_record()
if ch2==3:
break;

--------------------------------------------------------------------------------------

Ans 2

stack=[]
while(True):
print("1- Push \n 2-Pop \n 3-Display \n 4-Exit ")
ch=int(input(" Choice 1-4 "))
if ch==1:
st_no=int(input("roll no "))
st_name=input(" Name ")
L=[st_no,st_name]
stack.append(L)
elif ch==2:
st_no2,st_name2=stack.pop()
print(st_no2,st_name2)

elif ch==3:
len1=len(stack)
for i in range(len1-1,-1,-1):
print(stack[i])

else:
break

Queries

a)
select distinct address from employee;
b)
select * from employee where salary between 30000 and 40000;
c)
select * from employee where address in('bbk','lko');
d)
select * from employee order by emp_no desc;

You might also like