forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.py
More file actions
48 lines (34 loc) · 1.13 KB
/
Copy pathrobot.py
File metadata and controls
48 lines (34 loc) · 1.13 KB
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
class IndustrialRobot:
def __init__(self):
self.body = Body()
self.arm = Arm()
def rotate_body_left(self, degrees=10):
self.body.rotate_left(degrees)
def rotate_body_right(self, degrees=10):
self.body.rotate_right(degrees)
def move_arm_up(self, distance=10):
self.arm.move_up(distance)
def move_arm_down(self, distance=10):
self.arm.move_down(distance)
def weld(self):
self.arm.weld()
class Body:
def __init__(self):
self.rotation = 0
def rotate_left(self, degrees=10):
self.rotation -= degrees
print(f"Rotating body {degrees} degrees to the left...")
def rotate_right(self, degrees=10):
self.rotation += degrees
print(f"Rotating body {degrees} degrees to the right...")
class Arm:
def __init__(self):
self.position = 0
def move_up(self, distance=1):
self.position += 1
print(f"Moving arm {distance} cm up...")
def move_down(self, distance=1):
self.position -= 1
print(f"Moving arm {distance} cm down...")
def weld(self):
print("Welding...")