I'm encountering an issue with the output formatting in my Python code related to displaying the hierarchy of employees in a company. Despite implementing the logic correctly, the output is displaying individual characters instead of complete strings representing employees.
Here's a brief overview of the problem:
- I have a Python program that manages employee information within a company.
- One of the functionalities of the program is to display the hierarchy of employees starting from a given manager.
- I'm constructing the hierarchy, but when printing the output, it's showing individual characters instead of complete strings representing employees.
- I've ensured that the code logic for constructing the hierarchy is correct, but there seems to be an issue with how the output is being processed or displayed.
Here is a sample I/O statement.
Sample input:
EMPLOYEE_HIERARCHY Kevin
Sample output:
EMPLOYEE_HIERARCHY :>
Employee [name=Kevin, gender=MALE]
Employee [name=Manurola, gender=FEMALE] Employee [name=Nivan, gender=MALE] Employee [name=Yash, gender=MALE]
Employee [name=Simmy, gender=FEMALE]
My output:
EMPLOYEE_HIERARCHY :>
'E'
'm'
'p'
'l'
'o'
'y'
'e'
'e'
' '
'['
'n'
'a'
'm'
'e'
'='
'K'
'e'
'v'
'i'
'n'
','
' '
'g'
'e'
'n'
'd'
'e'
'r'
'='
'G'
'e'
'n'
'd'
'e'
'r'
'.'
'M'
'A'
'L'
'E'
']'
'\n'
' '
' '
'E'
'm'
'p'
'l'
'o'
'y'
'e'
'e'
' '
'['
'n'
'a'
'm'
'e'
'='
'M'
'a'
'n'
'u'
'r'
'o'
'l'
'a'
','
' '
'g'
'e'
'n'
'd'
'e'
'r'
'='
'G'
'e'
'n'
'd'
'e'
'r'
'.'
'F'
'E'
'M'
'A'
'L'
'E'
']'
'\n'
' '
' '
'E'
'm'
'p'
'l'
'o'
'y'
'e'
'e'
' '
'['
'n'
'a'
'm'
'e'
'='
'N'
'i'
'v'
'a'
'n'
','
' '
'g'
'e'
'n'
'd'
'e'
'r'
'='
'G'
'e'
'n'
'd'
'e'
'r'
'.'
'M'
'A'
'L'
'E'
']'
'\n'
' '
' '
' '
' '
'E'
'm'
'p'
'l'
'o'
'y'
'e'
'e'
' '
'['
'n'
'a'
'm'
'e'
'='
'S'
'i'
'm'
'm'
'y'
','
' '
'g'
'e'
'n'
'd'
'e'
'r'
'='
'G'
'e'
'n'
'd'
'e'
'r'
'.'
'F'
'E'
'M'
'A'
'L'
'E'
']'
'\n'
' '
' '
'E'
'm'
'p'
'l'
'o'
'y'
'e'
'e'
' '
'['
'n'
'a'
'm'
'e'
'='
'Y'
'a'
's'
'h'
','
' '
'g'
'e'
'n'
'd'
'e'
'r'
'='
'G'
'e'
'n'
'd'
'e'
'r'
'.'
'M'
'A'
'L'
'E'
']'
This is my implementation:
def get_employee_hierarchy(self, manager_name: str) -> List[str]:
output_tree = []
def build_hierarchy(employee_name, level=0):
employee = self._employee_book.get(employee_name)
if not employee:
return []
indent = "\t" * level
employee_str = f"{indent}Employee [name={employee.get_name()}, gender={employee.get_gender().value}]"
hierarchy = [employee_str]
direct_reports = self.get_direct_reports(employee_name)
for direct_report in direct_reports:
hierarchy.extend(build_hierarchy(direct_report.get_name(), level + 1))
return hierarchy
hierarchy = build_hierarchy(manager_name)
output_tree.extend(hierarchy)
# Join the hierarchy items into a single string with newlines
output_str = '\n'.join(output_tree)
return output_str
I'm seeking assistance in identifying and resolving this output formatting issue so that the hierarchy of employees can be displayed correctly.
Any insights or suggestions on how to fix this issue would be greatly appreciated. Thank you!