In: Computer Science
Hi, I would be grateful for some helot with this Python problem. Your task is to implement the simple elevator in Python using classes. The default strategy is the simple "start at the bottom, go to the top, then go to the bottom". Can you write a better strategy, one that is more efficient? Description / Specification Create three classes: Building, Elevator, and Customer. Equip the building with an elevator. Ask user to customize the number of floors and the number of customers. Program should have error checking to make sure the user inputs are valid. For example, if a user gives non-integer inputs, notify the user that the inputs are incorrect and prompt again. Each customer starts from a random floor, and has a random destination floor. Each customer will use the elevator only once, i.e., when a customer moves out of the elevator, he/she will never use it again. When all customers have reached their destination floor, the simulation is finished. Part of the grade on this assignment will be the appropriateness of your classes, methods, and any functions you use. The quality of the code will matter as well as the performance. All class methods require a docstring for a general description of the method. Implement both your own strategy and the default strategy and compare. Your strategy does not have to be better but the comparison is required. Don't use any global variables. Notes and Hints In your main function, at the beginning ask the user for the number of floors and the number of customers which can be used to create an instance of Building. Then we only need to call the run and output methods repeatedly in a while loop. Randomly select the floors (to and from) for each customer. Use the randint function from the random module. To compare efficiency of strategy, count the number of floors visited for your strategy versus the default strategy. Make a demo to create usable output from your simulation.
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