Write a Python class Elevator that simulates an elevator system within a building, with methods to move between floors, call the elevator, and display the current floor. The building has 10 floors, and the elevator starts on the ground floor.
Example 1:
Input: move(5), current_floor()
Output: 5
Example 2:
Input: move(3), call_elevator(7), current_floor()
Output: 7
Keep track of the current floor and provide methods to move the elevator and call the elevator to a specific floor.
class Elevator:
def __init__(self):
self.current_floor = 0
def move(self, floor):
self.current_floor = floor
def call_elevator(self, floor):
self.current_floor = floor
def current_floor(self):
return self.current_floor
# Example usage
elevator = Elevator()
elevator.move(5)
print(elevator.current_floor()) # Output: 5
elevator.call_elevator(7)
print(elevator.current_floor()) # Output: 7
Unlock AI & Data Science treasures. Log in!