Python电梯模拟问题

2 python oop

我有一个家庭作业,真的是我的面条.它涉及电梯模拟,该模拟采用用户输入的楼层数和使用电梯的人数.人们的起始楼层和目的地楼层是楼层内的随机数字.

我意识到我的代码非常稀疏,并且存在相当多的空白,但我真的不知道从哪里开始.

我需要在构建类中提供帮助,例如如何使run()和output()部分工作.任何其他提示将非常感谢和有帮助.请注意,我不是在寻找有人为我做代码,而是要握住我的手并告诉我要走哪条路.对我来说,课程似乎完全不可思议.

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    
Run Code Online (Sandbox Code Playgroud)

ret*_*ile 6

  • 您需要了解self 所有方法的参数.
  • 你需要了解__init__构造函数.
  • 您需要了解self.varible 您的成员变量.
  • 您需要了解如何设置 main功能.
  • 您需要了解如何 return从函数或方法中获取值.
  • 您需要了解如何global从函数或方法中分配变量.