-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass Elevator
49 lines (41 loc) · 1.18 KB
/
class Elevator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Elevator:
def __init__(self, bottom, top, current):
"""Initializes the Elevator instance."""
self.bottom = bottom
self.top = top
self.current = current
def up(self):
"""Makes the elevator go up one floor."""
if self.current < self.top:
self.current += 1
def down(self):
"""Makes the elevator go down one floor."""
if self.current > self.bottom:
self.current -= 1
def go_to(self, floor):
"""Makes the elevator go to the specific floor."""
self.current = floor
def __str__(self):
"""Bla bla bla"""
return "Current floor: {}".format(self.current)
elevator = Elevator(-1, 10, 0)
elevator.up()
elevator.current
elevator.down()
elevator.current
elevator.go_to(10)
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)