Pycharm
Hello, there is currently an error in my code where I am told the following:
Traceback (most recent call last):
File "C:/Users/thepe/PycharmProjects/CPE101Labs/Dunder Mifflin/Employee Managment/employee.py", line 1, in <module>
class employee:
File "C:/Users/thepe/PycharmProjects/CPE101Labs/Dunder Mifflin/Employee Managment/employee.py", line 67, in employee
employeeList.append(employeeList("Michael", 45, "Manager"))
TypeError: 'list' object is not callable
Here's my code:
class employee:
def __init__(self, name, age, position):
self.name = name
self.age = age
self.position = position
def display_employees(listOfEmployees):
print()
print("Employees in Dunder Mifflin are:")
print()
for item in listOfEmployees:
print(item.name + ",", str(item.age) + ",", item.position)
def allocate_department(listOfEmployees):
allocatedList = []
managementList = []
salesList = []
accountantList =[]
for employee in listOfEmployees:
if employee.positon == "Manager" or "Manager" in employee.position:
managementList.append(employee)
elif employee.position == "Salesperson" or "Salesperson" in employee.position:
salesList.append(employee)
elif employee.position == "Accountant" or "Accountant" in employee.position:
accountantList.append(employee)
else:
pass
allocatedList.append(managementList)
allocatedList.append(salesList)
allocatedList.append(accountantList)
return allocatedList
def display_department_employees(listOfDep):
print()
print("The individual employees in each department are shown below:")
print("-----------------------------------------------------------")
print()
n = 1
for dep in listOfDep:
if n == 1:
print("Management")
print("----------")
elif n == 2:
print("Salespersons:")
print("-------------")
for emp1 in dep:
print(emp1.name + ",", str(emp1.age), + ",", emp1.position)
print()
n += 1
def head_of_department(listOfDep):
for dep in listOfDep:
max = 0
for emp1 in dep:
if emp1.age > max:
max = emp1.age
for emp1 in dep:
if max == emp1.age:
emp1.position = "Head" + emp1.position
employeeList = []
employeeList.append(employeeList("Michael", 45, "Manager"))
employeeList.append(employeeList("Dwight", 40, "Assistant to the Manager"))
employeeList.append(employeeList("Jim", 35, "Manager"))
employeeList.append(employeeList("Pam", 30, "Receptionist"))
employeeList.append(employeeList("Angela", 32, "Accountant"))
employeeList.append(employeeList("Kevin", 42, "Accountant"))
employeeList.append(employeeList("Oscar", 40, "Accountant"))
employeeList.append(employeeList("Stanley", 55, "Salesperson"))
employeeList.append(employeeList("Phyllis", 45, "Salesperson"))
employeeList.append(employeeList("Andy", 38, "Salesperson"))
employeeList.append(employeeList("Ryan", 30, "Salesperson"))
employeeList.append(employeeList("Creed", 55, "Salesperson"))
employeeList.display_employees(employeeList)
employeeList.display_department_employees(employeeList.allocate_department(employeeList))
employeeList.head_of_department(employeeList.allocate_department(employeeList))
print("#####################################")
print("Head of department allocation done!!!")
print("#####################################")
employeeList.display_department_employees(employeeList.allocate_department(employeeList))
print()
Step by step
Solved in 2 steps