0

我有这个电梯任务,我被困在一个地方。我有一个包含客户列表的建筑对象。我正在尝试一种让客户进入电梯的方法 - 客户被附加到电梯列表中,但无法找到从建筑物列表中删除该客户的方法:尝试过dellist.remove(item)没有任何乐趣。谁能指出我正确的方向?

class building(object):  
    def __init__(self, floors = 0, customerNo = 0,):
        self.floors = 0
        self.myE = elevator()
        self.customerNo = 0
        self.customersWaiting = []
        self.customersTransported = []

    def initCustomers(self):        
        cnt = 1
        cust = cnt
        while cnt <= myB.customerNo :
            floor = random.randint(0, self.floors - 1)
            destination = random.randint(0, self.floors - 1)
            cust = customer(cnt, floor , destination )
            self.customersWaiting.append(cust)
            cnt +=1

class customer(object):
    def __init__(self,cnt, floor = 0, destination = 0):
        self.cnt = cnt
        self.floor = floor
        self.destination = destination

    def enterElevator(self):
        for cust in myB.customersWaiting :
            if myB.myE.lvl == self.floor :
                myB.myE.customersIn.append(self)
                #del cust(self)
                #myB.customersWaiting.remove(self)
            else:
                pass
4

1 回答 1

0

您好,这是我的一些建议:

1)建筑物应该有N层,你可以有一个buildingFactory来创建n层的建筑物。

def createBuilding(self, N):
    return building = Building(N)
class Building:
    def __init__(self, N):
        self.floorWatingList= []
        for f in range(N):
            self.floorWaitingList.append() = []

2) 使用 clear() 或 pop() 方法从列表中删除客户

for c in building.floorWaitingList[current]:
      elvator.enter(c)
building.floorWaitingList.clear()
于 2013-04-25T00:56:49.397 回答