Guest User

Untitled

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