The code below defines an Elevator class. The elevator has a current floor, it also has a top and a bottom floor.
Those are the minimum and maximum floors it can go to.
Fill in the blanks to make the elevator go through the floors requested.
class Elevator:
def __init__(self, bottom, top, current):
"""Initializes the Elevator instance."""
self.bottom = 0
self.top = 0
self.current = 0
def up(self):
"""Makes the elevator go up one floor."""
self.current += 1
def down(self):
"""Makes the elevator go down one floor."""
self.current -= 1
def go_to(self, floor):
"""Makes the elevator go to the specific floor."""
self.current = floor
def __str__(self):
return '"Current floor: {}"'.format(self.current)
elevator = Elevator(-1, 10, 0)
elevator.up()
elevator.current #should output 1
print(elevator.current)
elevator.down()
elevator.current #should output 0
print(elevator.current)
elevator.go_to(10)
elevator.current #should output 10
print(elevator.current)
# Go to the top floor. Try to go up, it should stay. Then go down.
elevator.go_to(10)
elevator.up()
elevator.down()
print(elevator.current) # should be 9
# Go to the bottom floor. Try to go down, it should stay. Then go up.
elevator.go_to(-1)
elevator.down()
elevator.down()
elevator.up()
elevator.up()
print(elevator.current) # should be 1
elevator.go_to(5)
print(elevator)
self.current += 1
is in range? If it is not in range, what should you do about it?