Advertisements
Advertisements
Question
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 function to input employee data and append it to a binary file.
Code Writing
Advertisements
Solution
import pickle
def append_data():
with open("emp.dat", '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: "))
pickle.dump([employee_id, employee_name, department, salary], file)
print("Employee data appended successfully.")shaalaa.com
Is there an error in this question or solution?
