目前的错误是cust_list.append(customer(i, floor_count))
,它表示名称customer
未定义。任何帮助将不胜感激。
这个程序在设计上是非常基础的(说实话,我对这个主题很新),而且此刻电梯再次上升并再次下降。该程序一直有效,直到您进入楼层/客户后,它才会崩溃。
import random
def main():
customer_count=int (input("how many customers?:"))
floor_count =int (input("How many floors?:"))
cust_list=[]
for i in range(1, customer_count+1):
cust_list.append(customer(i, floor_count))
lift=Lift(floor_count, cust_list)
building=Building(floor_count, cust_list, lift)
class Building(object):
def __init__(self, num_of_floors, customer_list, lift):
self.customers=customer_list
self.total_floors=num_of_floors
def work(self):
while elevator.floor !=0:
for customer in self.customers:
if elevator.floor==customer.on_floor:
elevator.reg_list.append(customer)
customer.indicator=1
elif elevator.floor==customer.going_floor:
elevator.reg_list.remove(customer)
customer.indicator=0
customer.fin=1
elevator.move()
class Customers(object):
def __init__(self, iden, num_of_floors, curnt_floor, dest_floor,
in_lift, finished=0):
self.id=iden
self.indicator=in_lift
self.fin=finished
#self.cfloor=curnt_floor
curnt_floor=random.randint(1, num_of_floors)
self.on_floor=curnt_floor
dest_floor=random.randint(1, num_of_floors)
self.going_floor=dest_floor
class Lift(object):
def __init__(self, num_of_floors, register_list, direction="up",
curnt_floor=1):
self.total_floors=num_of_floors
self.reg_list=[]
self.floor=curnt_floor
self.direct=direction
def move(self):
if self.total_floors==self.floor:
self.direct="down"
if self.direct=="up":
self.floor+=1
else:
self.floor-=1
def register_customer(self,customer):
self.reg_list.append(customer)
def done_customer(self, customer):
self.reg_list.remove(customer)
if __name__ == "__main__":
main()
答案 0 :(得分:0)
它说customer is not defined
,因为您在定义之前使用了术语customer
。查看相关行前main()
中的所有代码,并注意您从未提及customer
。