Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Class Method Unreachable

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

>Solution :

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

E.print_self_employees()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading