This is in Python 3.3.
So I have two classes: Employee
and Zone
. Zone
takes the Employee
objects I create and puts their name
and ID
into a list
. I want the remove_employee
method to take an employee's ID
in a string, find the employee that matches the ID
, and remove them from the list. Here's what I have so far:
class Employee:
employee_count = 0
def __init__(self, name, employee_id):
self._name = name
self._employee_id = employee_id
Employee.employee_count += 1
def get_employee_id(self):
return self._employee_id
class Zone:
def __init__(self, name="Kitchen", employees=[]):
self._name = name
self._employees = employees
def add_employee(self, employee):
self._employees += [employee]
def remove_employee(self, employee_id):
for employee_id in self._employees:
self._employees.remove(employee_id)
def number_of_employees(self):
return len(self._employees)
And when I try to run this:
John = Employee('John', 'F12345')
Jack = Employee('Jack', 'F23514')
Jane = Employee('Jane', 'F10253')
Kitchen = Zone()
Kitchen.add_employee(John)
Kitchen.add_employee(Jack)
Kitchen.add_employee(Jane)
Kitchen.remove_employee('F12345') #John's ID
It removes John and Jane from the list, instead of just John. I'm very new to programming and I'm completely stumped by how to write remove_method()
.
Any help would be greatly appreciated!