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

Binary File Program

Uploaded by

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

Binary File Program

Uploaded by

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

BINARY FILE PROGRAM

Write a program to create a BINARY file “Employee.dat” and insert the following data
into the file and perform the following task:
Eid Name Salary Age
E01 Aman 98000 34
E02 Shreya 87000 45
E03 Rahul 67000 23
E04 Rajesh 92000 67

import pickle
def write():
f=open("E:\Employee.dat","wb")
for i in range(4):
Eid=input("Enter Employee Id")
Name=input("Enter name")
Sal=float(input("Enter Salary"))
Age=input("Enter Age")
l=[Eid,Name,Sal,Age]
pickle.dump(l,f)
f.close()

Display the entire record of the file.

def display():
f=open("E:\Employee.dat ","rb")
print("The content of the file:")
f=pickle.load(f)
for i in l:
print(*i)
f.close()

Display the Name of those Employee whose Age is more than 50.

def display1():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
for i in l:
if i[3]>50:
print(*i)
f.close()
Display those content of the file whose name starting with R and ending with h.

def display1():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
for i in l:
if i[1][0]=="R" and i[1][-1]=="h":
print(*i)
f.close()

Decrease the Salary of “Aman” by 10% in the file.

def update():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
for i in l:
if i[1]=”Aman”:
i[2]=i[2]*1.1
f.close()
f1=open("E:\Employee.dat ","wb")
pickle.dump(l,f1)
f1.close()

Delete those records of students from the file whose salary is more than 70000.

def delete():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
m=[]
for i in l:
if i[2]<=70000:
m.append(i)
f.close()
f1=open("E:\Employee.dat ","wb")
pickle.dump(m,f1)
f1.close()

write()
display()
display1()
display2()
update()
display()
delete()
display()

You might also like