0% found this document useful (0 votes)
21 views1 page

Search Operations in Binary File

Uploaded by

rufussamuel29
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)
21 views1 page

Search Operations in Binary File

Uploaded by

rufussamuel29
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/ 1

import pickle

def search_employees_by_salary():
l=[]
file = open("emp.dat", "wb")
n = int(input("Enter the number of employees: "))
for i in range(n):
empcode = input("Enter Employee code: ")
Ename = input("Enter Employee Name: ")
salary = int(input("Enter salary: "))
emp_record = [empcode, Ename, salary]
l.append(emp_record)
pickle.dump(l,file)
file.close()
print("Data written to emp.dat successfully.\n")
f = open('emp.dat', 'rb')
employees = pickle.load(f)
Emp=[]
for employee in employees:
if employee[2]>500000:
Emp.append(employee)
if Emp==[]:
print("No such employee/s present!")
else:
print("Details of Employees with salary greater than 500000 is:")
for i in Emp:
print(i)
f.close()
print("Program Ends!")

search_employees_by_salary()

You might also like