美文网首页
day-13作业

day-13作业

作者: FansYuercero | 来源:发表于2018-08-01 17:36 被阅读0次

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

    • 能存多个员工信息
      (每个员工的信息有:姓名、年龄、工号、薪资、职位、部门)
    • 新员工入职(添加员工)
    • 员工离职(删除员工)
    • 查看某个员工的信息
    • 查询薪资最高的员工
    • 查询指定部门中所有员工的平均薪资
    • 求整个公司的员工的平均年龄
    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('寰宇集团')
        print('1.添加员工\n2.查找员工\n3.删除员工\n4.查看所有员工\n5.查看最高薪资\n6.查部门平均工资\n7.查公司平均工资\nq.退出')
        choose = input('>>>')
        if choose=='1':
            while True:
                clsone.add_employees()
                print('1.继续添加\n2.返回上级')
                choose1 = input('>>>')
                if choose1 !='1'or choose1=='2':
                    break
                continue
    
        elif  choose=='2':
            while  True:
                clsone.check_employees()
                print('1.继续查看\n2.返回上级')
                choose2 = input('>>>')
                if choose2 != '1' or choose2 == '2':
                    break
                continue
        elif choose =='3':
            while True:
                clsone.del_employees()
                print('1.继续删除\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.继续查询\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
    
    

    相关文章

      网友评论

          本文标题:day-13作业

          本文链接:https://www.haomeiwen.com/subject/cgvrvftx.html