Home > OS >  Class Method Unreachable
Class Method Unreachable

Time:11-02

In the code is a class Company wherein is an employe_base, *which contains employee objects . With the function print_self_employees, I try to modify a list employees and print it.

class Company():
    def __init__(self, name, minimum_hiring_grades, required_work_experience_years,employee_leaves, employee_bonus_percent, employee_working_days) -> None:
        self.name = name
        self.minimum_hiring_grades = minimum_hiring_grades
        self.required_work_experience_years =  required_work_experience_years
        self.employee_leaves = employee_leaves
        self.employee_bonus_percent = employee_bonus_percent
        self.employee_working_days = employee_working_days
        self.employee_base = []
        self.employees = []

    def hire_employee(self, employee) -> None:
        if employee.grades_percent_average >= self.minimum_hiring_grades and employee.work_experience_years >= self.required_work_experience_years:
            print("You are hired!")
            self.employee_base.append(employee)
            employee.has_job = True
            employee.working_days = self.employee_working_days
            employee.bonus_percent = self.employee_bonus_percent
            employee.available_leaves = self.employee_leaves
            employee.salary_dollars = employee.grades_percent_average   employee.work_experience_years * 1000
            employee.id = employee
        else:
            print("You did not meet our requirements.")

    def give_leaves_employee(self, employee, leaves_required) -> None:
        if leaves_required <= 3 and employee.available_leaves - leaves_required >= 0:
            employee.available_leaves -=  leaves_required
            print("Leaves are granted.")
        else:
            print("Leaves can't be granted.")

    def print_self_employees(self):
        self.employees = [employee.name for employee in self.employee_base]  
        print(self.employees)

Here, print_self_employees produces no result instead of printing. I tried changing the print to just "hello", but that didn't work either. The function seems to be completely unreachable, but has no indication of being so in my IDE VSCode. Could someone point out an error I seem to be missing

My code is called like so:

E = Company("E", 90, 5, 30, 25, 300)
r = Employee("r", 90, 5)
a = Employee("a", 91, 7)
a.apply_in_company(EY)
r.apply_in_company(EY)
E.print_self_employees
print(E.employee_base)

CodePudding user response:

You need to be calling the print function rather than referencing it. Try:

E.print_self_employees()
  • Related