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

Binary File

The document contains Python functions for managing employee records in a binary file. It includes a function to input and append employee data with attributes like ID, name, department, and salary, and another function to update the salary of employees in the IT department to 200000. The use of the 'pickle' module allows for serialization and deserialization of employee data.

Uploaded by

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

Binary File

The document contains Python functions for managing employee records in a binary file. It includes a function to input and append employee data with attributes like ID, name, department, and salary, and another function to update the salary of employees in the IT department to 200000. The use of the 'pickle' module allows for serialization and deserialization of employee data.

Uploaded by

arrowgaming54321
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

"""Mr.

Ravi, a manager at a tech company, needs to maintain records of


employees. Each
record should include: Employee_ID, Employee_Name, Department and Salary.
Write the Python functions to:
I.
Input employee data and append it to a binary file.
II. Update the salary of employees in the "IT" department to 200000.
"""
import pickle
def append_data():
with open("[Link]", 'ab') as file:
employee_id = int(input("Enter Employee ID: "))
employee_name = input("Enter Employee Name: ")
department = input("Enter Department: ")
salary = float(input("Enter Salary: "))
[Link]([employee_id, employee_name, department, salary], file)
print("Employee data appended successfully.")
#[Link]()
append_data()

f = open('[Link]', 'rb')

bin = [Link]()
print(bin)

[Link]()

def update_data():
updated = False
employees = []
with open("[Link]", 'rb') as file:
try:
while True:
employee = [Link](file)
if employee[2] == "IT":
employee[3] = 200000
updated = True
[Link](employee)
except EOFError:
pass
with open("[Link]", 'wb') as file:
for employee in employees:
[Link](employee, file)
if updated:
print("Salaries updated for IT department.")
else:
print("No employee found in the IT department.")
#[Link]()
update_data()

You might also like