-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Example18.py
More file actions
48 lines (43 loc) · 1.14 KB
/
Class_Example18.py
File metadata and controls
48 lines (43 loc) · 1.14 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
"""
Add a method reflect_x to Point which returns a new Point, one which is the reflection of the point about the x-axis. For example, Point(3, 5).reflect_x() is (3, -5)
"""
class Point:
"""
Describes about the point on the graph
"""
def __init__(self, intX, intY):
"""
Initializes the variables
:param intX: assigns to x
:param intY: assigns to y
"""
self.x = intX
self.y = intY
def reflect_x(self):
"""
Returns a Point which reflects the x
:return: a Point Object
"""
self.x = self.x
self.y = -self.y
return Point(self.x,self.y)
def move(self, dx, dy):
"""
Movement of the value in that direction
:param dx: Number of units in the x direction
:param dy: Number of units in the y direction
:return:
"""
self.x += dx
self.y += dy
def __repr__(self):
"""
Represents the Point in the string format
:return:
"""
return f"Point({self.x},{self.y})"
p2=Point(3,5).reflect_x()
print(p2)
p3=Point(3,5)
p3.move(2,1)
print(p3)