14-作业(人力管理资源系统不完善版)

查询指定部门所有员工的平均公司没有实现
本来想写的数据类型是
data={
部门1:[{'name':员工1的姓名,'age':‘员工1的年龄’..},name':员工2的姓名,'age':‘员工2的年龄’..}],
部门2:[{'name':员工4的姓名,'age':‘员工4的年龄’..},name':员工4的姓名,'age':‘员工4的年龄’..}]
部门3:[{'name':员工6的姓名,'age':‘员工6的年龄’..},name':员工6的姓名,'age':‘员工6的年龄’..}]
}
不同部门有不同员工 ,员工下面有自己的员工信息
先写了员工的信息,后头写不出来怎么和部门对应。。

作业:
面向对象人力资源管理系统:

  • 能存多个员工信息
    (每个员工的信息有:姓名、年龄、工号、薪资、职位、部门)
  • 新员工入职(添加员工)
  • 员工离职(删除员工)
  • 查看某个员工的信息
  • 查询薪资最高的员工

- 查询指定部门中所有员工的平均薪资

  • 求整个公司的员工的平均年龄

(可以根据能力改善和添加功能,做到尽量贴近生活)

hr_data=[]
company_data=[]

class Person:
    '''员工'''

    def __init__(self):
        self._name = ''
        self._age = 0
        self._num = 0
        self._salary = 0
        self._postion = ''

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        if not name:
            raise ValueError('名字不能为空')

        self._name = name

    @property
    def age(self):
        return self._age

    @age.setter
    def age(self, age):
        if age < 18 or age > 60:
            raise ValueError('年龄太大或太小请重新输入')
        self._age = age

    @property
    def num(self):
        return self._num

    @num.setter
    def num(self, num):
        if not num:
            raise ValueError('编码不能为空')
        self._num = num

    @property
    def salary(self):
        return self._salary

    @salary.setter
    def salary(self, salary):
        if salary < 2000:
            raise ValueError('工资太低不符合公司标准')
        self._salary = salary

    @property
    def postion(self):
        return self._name

    @postion.setter
    def postion(self, postion):
        self._postion = postion

    # 员工入职,输入员工信息
    def input_data(self):
        person = {}
        self.name = input('输入员工名字:')
        self.age = int(input('输入员工年龄:'))
        self.num = 'cmp2018' + input('输入员工工号:')
        self.salary = int(input('输入员工工资'))
        self.postion = input('输入员工职位')
        person['name'] = self.name
        person['age'] = self.age
        person['num'] = self.num
        person['salary'] = self.salary
        person['postion'] = self.postion
        hr_data.append(person)
        print(hr_data)

    # 查找员工信息
    def look_for(self):
        human = input('输入你想要查看的员工:')
        for data in hr_data:
            if data['name'] == human:
                print(data)

    # 删除员工
    def delet_data(self):
        human = input('你想要删除的员工')
        for data in hr_data:
            if data['name'] == human:
                del data
                print('删除成功')

    # 求平均年龄
    def average_age(self):
        sum = 0
        count = 1
        for data in hr_data:
            age = data['age']
            sum += int(age)
            average = sum / count
            count += 1
        print('平均年龄为:%s' % average)
        return average

    # 求薪资最高的员工
    def max_salary(self):

        max = 0
        for data in hr_data:
            salary = data['salary']
            if max < salary:
                name = data['name']
                max = salary

        print('%s工资最高是%s元' % (name, max))
        return max

    def printmenu(self):
        print('——————————---——————————')
        print('1.添加员工')
        print('2.删除员工')
        print('3.查找员工信息')
        print('4.求员工的平均薪水')
        print('5.求薪资最高的员工')
        print('6.退出程序')
        print('添加员工的部门')

    def break_it(self):
        break_game = input('请按回车退出系统:')
        while break_game == '':
            print('程序结束~~')
            exit()




class Copmany(Person):
    def __init__(self):
        self._name =''
        self._department=''

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        self._name = name


    @property
    def department(self):
        return self._department

    @department.setter
    def department(self, department):
        self._department =department
    def add_data(self):

        data={}
        self.name =p1.name
        department = input('部门是')

        data[department]=self.name
        print(data)





if __name__ == '__main__':
    while True:
        p1 = Person()
        p1.printmenu()
        p1 = Copmany()
        choice = input('输入你想要进行的操作:')
        if choice == '1':
            p1.input_data()

        if choice == '2':
            p1.delet_data()
        if choice == '3':
            p1.look_for()
        if choice == '4':
            p1.average_age()
        if choice == '5':
            p1.max_salary()
        if choice == '6':
            p1.break_it()
        #没有实现
        if choice =='7':
            p1.add_data()

你可能感兴趣的:(14-作业(人力管理资源系统不完善版))