面向?qū)ο笕肆Y源管理系統(tǒng):
- 能存多個員工信息
(每個員工的信息有:姓名唉俗、年齡陌凳、工號、薪資须肆、職位匿乃、部門) - 新員工入職(添加員工)
- 員工離職(刪除員工)
- 查看某個員工的信息
- 查詢薪資最高的員工
- 查詢指定部門中所有員工的平均薪資
- 求整個公司的員工的平均年齡
from random import randint
class Employees:
def __init__(self,name,age,id,sex,salary,position,department):
self.name = name
self.age = age
self.sex = sex
self.id = id
self.salary = salary
self.position = position
self.department = department
def __str__(self):
return str('name is %s,age is %d,id is %s,sex is %s,salary is %s,position is %s,department is%s'%(self.name,self.age,self.id,self.sex,self.salary,self.position,self.department))
class Company:
def __init__(self,name='',employees=[]):
self.company_name = name
self.employees = employees
def add_employees(self):
name = input('employees\'name')
age = input('employees\'age')
sex = input('employees\'sex')
salary = input('employees\'salary')
position = input('employees\'position')
department = input('employees\'department')
id = 'RideoCos0001'+str(randint(1,100)).rjust(3,'0')
emp = Employees(name,int(age),id,sex,float(salary),position,department)
self.employees.append(emp)
def check_employees(self):
input_info = input('input the employees\'s name or id')
for item in self.employees:
if input_info == item.name or input_info == item.id:
print(item)
def check_all_employees(self):
for item in self.employees:
print(item)
def del_employees(self):
input_info = input('input the employees\'s name or id')
for item in self.employees[:]:
if input_info == item.name or input_info == item.id:
self.employees.remove(item)
def check_high(self):
list1 = []
for item in self.employees:
list1.append(item.salary)
print('the highest salary is%.2f'%max(list1))
def check_department(self):
department = input('input the department which you wonder checking')
list2 = []
for item in self.employees:
if department == item.department:
list2.append(item.salary)
print('this %s avg salary is %.2f'%(department,(sum(list2)/len(list2))))
def check_avg(self):
list3 = []
for item in self.employees:
list3.append(item.salary)
print('this company\'s avg salary is%.2f'%(sum(list3)/len(list3)))
while True:
print('*'*50)
clsone = Company('寰宇集團(tuán)')
print('1.添加員工\n2.查找員工\n3.刪除員工\n4.查看所有員工\n5.查看最高薪資\n6.查部門平均工資\n7.查公司平均工資\nq.退出')
choose = input('>>>')
if choose=='1':
while True:
clsone.add_employees()
print('1.繼續(xù)添加\n2.返回上級')
choose1 = input('>>>')
if choose1 !='1'or choose1=='2':
break
continue
elif choose=='2':
while True:
clsone.check_employees()
print('1.繼續(xù)查看\n2.返回上級')
choose2 = input('>>>')
if choose2 != '1' or choose2 == '2':
break
continue
elif choose =='3':
while True:
clsone.del_employees()
print('1.繼續(xù)刪除\n2.返回上級')
choose3 = input('>>>')
if choose3 != '1' or choose3 == '2':
break
continue
elif choose=='4':
while True:
clsone.check_all_employees()
print('1.返回上級')
choose4 = input('>>>')
if choose4==1:
break
break
elif choose == '5':
while True:
clsone.check_high()
print('1.返回上級')
choose5 = input('>>>')
if choose5 == 1:
break
break
elif choose == '6':
while True:
clsone.check_department()
print('1.繼續(xù)查詢\n2.返回上級')
choose6 = input('>>>')
if choose6 != '1' or choose6 == '2':
break
continue
elif choose == '7':
while True:
clsone.check_avg()
print('1.返回上級')
choose7 = input('>>>')
if choose7 == 1:
break
break
else:
break