Employee Roles with Polymorphism

Write a class hierarchy for an organization’s employees. Create a base class Employee and subclasses like Manager, Engineer, and Intern, each implementing methods for roles and responsibilities.

Example 1:

Input: Manager 
Output: "Role: Manager, Responsibilities: Managing team, setting goals"

Example 2:

Input: Intern
Output: "Role: Intern, Responsibilities: Learning, assisting"

Override the role() and responsibilities() methods in each subclass to return the role and responsibilities of the employee.

class Employee:
    def role(self):
        pass

    def responsibilities(self):
        pass

class Manager(Employee):
    def role(self):
        return "Manager"

    def responsibilities(self):
        return "Managing team, setting goals"

class Engineer(Employee):
    def role(self):
        return "Engineer"

    def responsibilities(self):
        return "Designing, developing, testing"

class Intern(Employee):
    def role(self):
        return "Intern"

    def responsibilities(self):
        return "Learning, assisting"

# Test the classes
manager = Manager()
print(f"Role: {manager.role()}, Responsibilities: {manager.responsibilities()}")  # Output: Role: Manager, Responsibilities: Managing team, setting goals

intern = Intern()
print(f"Role: {intern.role()}, Responsibilities: {intern.responsibilities()}")  # Output: Role: Intern, Responsibilities: Learning, assisting

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!