0% found this document useful (0 votes)
9 views2 pages

Batch1 Set A Binary

Uploaded by

poonamchy44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Batch1 Set A Binary

Uploaded by

poonamchy44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# BOARD ROLLNO :

# BATCH -1 SET A
'''Write an interactive menu driven program implementing user defined functions to
perform
three basic operations using list [ empno, empname, empsal] on emp.dat binary file
such as (8)
(i) Insert multiple records of employee in Binary File
(ii) Searching Record of employee in Binary File using eno
(iii) Display Records of employee from Binary file'''

# using list
import pickle

def create():
file=open("emp.dat","wb")
record=[]
n=int(input("Enter number of records"))
for i in range(n):
eno=int(input("Enter emp number"))
ename=input("Enter name")
esal=int(input("Enter salary"))
k=[eno,ename,esal]
record.append(k)
pickle.dump(record,file)
file.close()

def display():
k=[]
file=open("emp.dat","rb")
k=pickle.load(file)
print(k)
file.close()

def search():
k=[]
file=open("emp.dat","rb")
found=False
e=int(input("Enter employee number to be search"))
try:
while True:
k=pickle.load(file)
for i in k:
if i[0]==e:
print(k)
found=True
except EOFError:
if found==True:
print("REcord found")
else :
print("Record not found")
file.close()

ans='y'
while ans=='y' or ans=='Y':
print("1 Insert multiple records of employee in Binary File")
print("2 Searching Record of employee in Binary File using eno")
print("3 Display Records of employee from Binary file")
ch=int(input("Enter your choice "))
if ch==1:
create()
elif ch==2:
search()
elif ch==3:
display()
else:
print("Wrong choice enter")
ans=input("Press Y to cont..... the program")

'''
output
1 Insert multiple records of employee in Binary File
2 Searching Record of employee in Binary File using eno
3 Display Records of employee from Binary file
Enter your choice 1
Enter number of records2
Enter emp number101
Enter namesumit
Enter salary23000
Enter emp number102
Enter namesonu
Enter salary45000
Press Y to cont..... the programy

1 Insert multiple records of employee in Binary File


2 Searching Record of employee in Binary File using eno
3 Display Records of employee from Binary file
Enter your choice 2
Enter employee number to be search101
[[101, 'sumit', 23000], [102, 'sonu', 45000]]
REcord found
Press Y to cont..... the programy
1 Insert multiple records of employee in Binary File
2 Searching Record of employee in Binary File using eno
3 Display Records of employee from Binary file
Enter your choice 3
[[101, 'sumit', 23000], [102, 'sonu', 45000]]
Press Y to cont..... the programn

You might also like