-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise17_12.py
More file actions
66 lines (47 loc) · 1.45 KB
/
Exercise17_12.py
File metadata and controls
66 lines (47 loc) · 1.45 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Point:
""" Point class for representing and manipulating x,y coordinates. """
def __init__(self, initX, initY):
self.x = initX
self.y = initY
def getX(self):
return self.x
def getY(self):
return self.y
def __str__(self):
return "x=" + str(self.x) + ", y=" + str(self.y)
class Rectangle:
"""Rectangle class using Point, width and height"""
def __init__(self, initP, initW, initH):
self.location = initP
self.width = initW
self.height = initH
def getwidth(self):
return self.width
def getheight(self):
return self.height
def area(self):
return self.width * self.height
def perimeter(self):
return (self.width * 2) + (self.height * 2)
def transpose(self):
holdw = self.width
holdh = self.height
self.width = holdh
self.height = holdw
return "width=" + str(self.width) + ", height=" + str(self.height)
def test(self,x,y):
if x > self.width or y > self.height:
return False
else:
return True
def __str__(self):
return "width=" + str(self.width) + ", height=" + str(self.height)
loc = Point(0, 0)
r = Rectangle(loc, 10, 5)
r = Rectangle(Point(0, 0), 10, 5)
print(r.test(0,0))
print(r.test(3,3))
print(r.test(3,7))
print(r.test(3,5))
print(r.test(3,4.999999))
print(r.test(-3,-3))