Guest User

Untitled

a guest
Feb 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import time
  2.  
  3. 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}
  4. floors_list = floors_dict.keys()
  5. floor_dict = dict((v,k) for k,v in floors_dict.items())
  6.  
  7. print("Welcome to the lift! We are asuming that you're on ground floor and starting the lift for you...")
  8. print("Please input the floor you want to go. We have listed the options for you.\n %s"%','.join(floors_list))
  9.  
  10.  
  11. current_floor_of_lift = 0 #Ground Floor
  12. current_floor_of_user = 0 #Ground Floor
  13. door_status = 0 #0-closed, 1-Opened
  14.  
  15. def opendoor():
  16. print("Opening lift door...")
  17. time.sleep(2)
  18.  
  19. def closedoor():
  20. print("Closing lift door...")
  21. time.sleep(2)
  22.  
  23. def move(current_floor, destination_floor):
  24. if current_floor < destination_floor:
  25. starting_floor = current_floor +1
  26. ending_floor = destination_floor+1
  27. step = 1
  28. elif destination_floor < current_floor:
  29. starting_floor = current_floor -1
  30. ending_floor = destination_floor-1
  31. step = -1
  32. else:
  33. current_floor_of_user = current_floor
  34. current_floor_of_lift = current_floor
  35.  
  36. for each_floor in range(starting_floor, ending_floor, step):
  37. print('Moving to %s-floor'%floor_dict[each_floor])
  38. time.sleep(3)
  39. current_floor_of_user = each_floor
  40. current_floor_of_lift = each_floor
  41.  
  42. return current_floor_of_user, current_floor_of_lift
  43.  
  44. while True:
  45. if door_status == 0:
  46. opendoor()
  47. door_status = 1
  48. print("The lift is on %s-floor"%floor_dict[current_floor_of_lift])
  49. destination_floor = input("Enter Floor here: ")
  50. #print(type(desination_floor))
  51.  
  52. if destination_floor not in floors_list:
  53. print('Error! You have entered the wrong floor, Please Input again.')
  54. continue
  55. else:
  56. print('Thanks for the input! we are taking you to your destination floor.')
  57. closedoor()
  58. door_status = 0
  59. destination_floor = floors_dict.get(destination_floor)
  60. current_floor_of_user, current_floor_of_lift = move(current_floor_of_lift, destination_floor)
  61. print("We have reached to %s-floor"%floor_dict[current_floor_of_lift])
  62. if door_status == 0:
  63. opendoor()
  64. door_status = 1
Add Comment
Please, Sign In to add comment