Company Employee Tracker

Implement a Python class Employee that keeps track of employees in a company. The class should keep track of their names, positions, and salaries. Include methods to add employees, remove employees, give raises, and promote employees.

Example 1:

company = Employee()
company.add_employee("John", "Engineer", 80000)
company.promote_employee("John", "Senior Engineer")
company.give_raise("John", 10000)
('John', 'Senior Engineer', 90000)

You can use a Python dictionary to store the employees data, with names as keys and a tuple or a list as values, including positions and salaries.

class Employee:
    def __init__(self):
        self.employees = {}

    def add_employee(self, name, position, salary):
        self.employees[name] = [position, salary]

    def remove_employee(self, name):
        if name in self.employees:
            del self.employees[name]

    def give_raise(self, name, raise_amount):
        if name in self.employees:
            self.employees[name][1] += raise_amount

    def promote_employee(self, name, new_position):
        if name in self.employees:
            self.employees[name][0] = new_position

    def get_employee_info(self, name):
        if name in self.employees:
            return (name,) + tuple(self.employees[name])

© Let’s Data Science


Unlock AI & Data Science treasures. Log in!