Answer:
Check the explanation
Explanation:
from Employee import *
import pickle
import random
def unpickle_employee(filename):
file=open(filename,'rb')
data=pickle.load(file)
file.close()
return data
def pickle_employee(data,filename):
file=open(filename,'wb')
pickle.dump(data,file)
file.close()
if __name__=='__main__':
filename="Employees.dat"
'''
E=Employee("Ajay",1,"R&D","Manager")
data={}
data[1]=E
pickle_employee(data,filename)
'''
data=unpickle_employee(filename)
while True:
print("\nData In Employee.dat")
for d in data:
print("Employe data: ",data[d].get_name(),"({},{},{})".
format(data[d].get_id_number(),data[d].get_department(),data[d].get_job_title()))
print("\n\n\t\tMenu")
print("To add new Employee, Enter a")
print("To update any Employee, Enter u")
print("To delete any Employee, Enter d")
print("Enter anything to quit")
choice=input("Enter: ")
if choice=='a':
id_number=random.randrange(100,200,1)
while id_number in data:
id_number+=1
if id_number>=200:
id_number=100
name=input("Enter the Name: ")
department=input("Enter the Department: ")
job_title=input("Enter the job title: ")
E=Employee(name,id_number,department,job_title)
data[id_number]=E
elif choice=='u':
id_number=int(input("Enter the Employee id_number to update: "))
for d in data:
print(id_number,d,d==id_number)
if id_number in data:
print("Employe data: ",data[id_number].get_name(),"({},{})".
format(data[id_number].get_department(),data[id_number].get_job_title()))
print("\nPlease Enter the details")
name=input("Enter the Name: ")
department=input("Enter the Department: ")
job_title=input("Enter the job title: ")
E=Employee(name,id_number,department,job_title)
data[id_number]=E
else:
print("Employee doesn't exist\n")
elif choice=='d':
id_number=int(input("Enter the Employee id_number to delete: "))
if id_number in data:
print("Employe data: ",data[id_number].get_name(),"({},{})".
format(data[id_number].get_department(),data[id_number].get_job_title()))
choice=input("\nPlease Enter y to confirm, anything else to cancel: ")
if choice=='y':
del data[id_number]
else:
print("Employee doesn't exist\n")
else:
break
pickle_employee(data,filename)