Python 员工管理系统:StaffManager 类实现
class StaffManager: def init(self, user, password): self.staffLists = [] self.user = user self.password = password
def addStaff(self, user, password, new_staff):
if self.user == user and self.password == password:
self.staffLists.append(new_staff)
print('员工添加成功')
else:
print('管理员账号或密码错误')
def findStaff(self, user, password, staff_id):
if self.user == user and self.password == password:
for staff in self.staffLists:
if staff.id == staff_id:
return staff
print('不存在该员工')
else:
print('管理员账号或密码错误')
def updateStaffInfo(self, user, password, staff_id, new_staff):
if self.user == user and self.password == password:
for i in range(len(self.staffLists)):
if self.staffLists[i].id == staff_id:
self.staffLists[i] = new_staff
print('员工信息更新成功')
return
print('不存在该员工')
else:
print('管理员账号或密码错误')
def deleteStaff(self, user, password, staff_id):
if self.user == user and self.password == password:
for i in range(len(self.staffLists)):
if self.staffLists[i].id == staff_id:
del self.staffLists[i]
print('员工删除成功')
return
print('不存在该员工')
else:
print('管理员账号或密码错误')
原文地址: https://www.cveoy.top/t/topic/osnM 著作权归作者所有。请勿转载和采集!