Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- floors_dict = {'B3': -3, 'b3': -3, 'B2': -2, 'b2': -2, 'B1': -1, 'b1': -1, 'G': 0, 'g': 0, '1': 1, '2':2 , '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, '10':10, '11':11, '12':12}
- floors_list = floors_dict.keys()
- floor_dict = dict((v,k) for k,v in floors_dict.items())
- print("Welcome to the lift! We are asuming that you're on ground floor and starting the lift for you...")
- print("Please input the floor you want to go. We have listed the options for you.\n %s"%','.join(floors_list))
- current_floor_of_lift = 0 #Ground Floor
- current_floor_of_user = 0 #Ground Floor
- door_status = 0 #0-closed, 1-Opened
- def opendoor():
- print("Opening lift door...")
- time.sleep(2)
- def closedoor():
- print("Closing lift door...")
- time.sleep(2)
- def move(current_floor, destination_floor):
- if current_floor < destination_floor:
- starting_floor = current_floor +1
- ending_floor = destination_floor+1
- step = 1
- elif destination_floor < current_floor:
- starting_floor = current_floor -1
- ending_floor = destination_floor-1
- step = -1
- else:
- current_floor_of_user = current_floor
- current_floor_of_lift = current_floor
- for each_floor in range(starting_floor, ending_floor, step):
- print('Moving to %s-floor'%floor_dict[each_floor])
- time.sleep(3)
- current_floor_of_user = each_floor
- current_floor_of_lift = each_floor
- return current_floor_of_user, current_floor_of_lift
- while True:
- if door_status == 0:
- opendoor()
- door_status = 1
- print("The lift is on %s-floor"%floor_dict[current_floor_of_lift])
- destination_floor = input("Enter Floor here: ")
- #print(type(desination_floor))
- if destination_floor not in floors_list:
- print('Error! You have entered the wrong floor, Please Input again.')
- continue
- else:
- print('Thanks for the input! we are taking you to your destination floor.')
- closedoor()
- door_status = 0
- destination_floor = floors_dict.get(destination_floor)
- current_floor_of_user, current_floor_of_lift = move(current_floor_of_lift, destination_floor)
- print("We have reached to %s-floor"%floor_dict[current_floor_of_lift])
- if door_status == 0:
- opendoor()
- door_status = 1
Add Comment
Please, Sign In to add comment