Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views8 pages

Binary File Program

Uploaded by

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

Binary File Program

Uploaded by

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

Write a program in a create a binary file

“employee.dat” having four field


(empid, empname, salary, age) and contain
following data.

E01 ROHIT 50000 34


E02 MANAS 60000 27
E04 VINAY 65000 40
import pickle
r=[]
n=int(input(“Enter number of employee”))
for I in range(n):
empid=input("Enter Emp id")
empname=input("Enter name")
salary=int(input("Enter salary"))
age=int(input("enter age"))
data=[empid,empname,salary,age]
r.append(data)
f=open("employee.dat","wb")
pickle.dump(r,f)
print("Record added")
f.close()
Write a program to display the record of
those employee from the binary file
“employee.dat” whose name is starting
with ‘M’.
import pickle
f=open("employee.dat","rb")
s=pickle.load(f)
found=0
for R in s:
if R[1][0]=='M':
print(R[0],R[1],R[2],R[3])
found+=1
if found==0:
print(“Not found")
f.close()
Write a program to increase the salary by
10% for those employee whose salary is
more than 58000 from a binary file
“employee.dat”.
import pickle
f=open("employee.dat","rb")
s=pickle.load(f)
found=0
for R in s:
if R[2]>=58000 :
R[2]=1.1*R[2]
found+=1
f.close()
f=open("employee.dat",“wb")
if found>0:
f.seek(0)
pickle.dump(s,f)
print("salary updated")
f.close()
Write a program to delete those record of
employee from a binary file “employee.dat”
whose salary is less than 55000.
import pickle
f=open("employee.dat","rb")
s=pickle.load(f)
found=0
for R in s:
if R[2]>55000:
s.remove(R)
found+=1
f=open("employee.dat",“wb")
if found>0:
f.seek(0)
pickle.dump(s,f)
print(“Record deleted")
f.close()

You might also like