Skip to content

Commit 64a089e

Browse files
Handle go_to for the current floor as well, and start with elevator door closed
1 parent 9a99f9b commit 64a089e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

elevator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, floors):
1414
self.current_floor = 1
1515
self.top_floor = floors
1616
self.busy = False # if the elevator is busy
17-
self.door_open = True # if the door is open
17+
self.door_open = False # if the door is open
1818
self.going_up = True # if the elevator is (or was last) going up
1919
self.go_to = dict() # status of floors to be visited by elevator
2020
for x in range(floors):
@@ -60,7 +60,7 @@ def go_to_floor(self, target_floor):
6060

6161
def next_floor_up(self):
6262
"""Returns the next floor above the current floor to go to or None"""
63-
for f in range(self.current_floor+1, self.top_floor+1):
63+
for f in range(self.current_floor, self.top_floor+1):
6464
if self.go_to[f] == True:
6565
return f
6666
return None
@@ -93,8 +93,8 @@ def run(self):
9393
else:
9494
# Work to do
9595
self.busy = True
96-
self.close_door()
9796
self.go_to_floor(next_floor)
9897
self.go_to[next_floor] = False
9998
self.open_door()
10099
wait(5, "Loading/unloading elevator")
100+
self.close_door()

0 commit comments

Comments
 (0)