我有一个家庭作业任务,这真的让我头疼。它涉及一个电梯模拟,需要用户输入楼层数和使用电梯的人数。人们的出发楼层和目的地楼层是楼层内的随机数字。
我认识到,我的法典非常稀少,存在一些差距,但我确实不知道从哪里走。
我需要在建筑类别内提供帮助,例如如何使(或)产出部分发挥作用。 任何其他建议都会得到高度赞赏和帮助。 请注意,我并不指望有人为我做法典,而是想把我的手交给我,告诉我什么路要走。 班级似乎对我完全是神秘的。
import random
floors=raw_input( Please enter the number of floors for the simulation: )
while floors.isalpha() or floors.isspace() or int(floors) <=0:
floors=raw_input( Please re enter a digit for number of floors: )
customers=raw_input( Please enter the number of customers in the building: )
while customers.isalpha() or customers.isspace() or int(customers) <0:
customers=raw_input( Please re enter a digit for number of customers: )
count = 1
class building:
def num_of_floors():
num_of_floors = floors
def customer_list():
customer_list = customers
def run(self):
def output(self):
print elevator.cur_floor
class elevator:
def num_of_floors():
building.num_of_floors
def register_list():
register_list = []
def cur_floor(building):
cur_floor = 1
def direction(self):
if elevator.cur_floor == 1:
direction = up
if elevator.cur_floor == floors:
direction = down
def move(self):
if elevator.direction == up:
cur_floor +=1
if elevator.direction == down:
cur_floor -=1
def register_customer(self, customer):
register_list.append(customer.ID)
def cancel_customer (self, customer):
register_list.remove(customer.ID)
class customer:
def cur_floor(customer):
cur_floor = random.randint(0,int(floors))
def dst_floor(customer):
dst_floor = random.randint(0,int(floors))
while dst_floor == cur_floor:
dst_floor = random.randint(0,int(floors))
def ID():
cust_id = count
count+=1
def cust_dict(cust_id,dst_floor):
cust_dict = {cust_id:dst_floor}
def in_elevator():
in_elevator = 0
if customer.ID in register_list:
in_elevator = 1
def finished():
if customer.ID not in register_list:
pass