-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr9.py
More file actions
43 lines (32 loc) · 1.26 KB
/
Copy pathpr9.py
File metadata and controls
43 lines (32 loc) · 1.26 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
class Point(object):
"""Represents a point in 2d space"""
class Rectangle(object):
"""Represents a rectangle in 2d space"""
rectangle = Rectangle()
bottom_left = Point()
bottom_left.x = 3.0
bottom_left.y = 5.0
top_right = Point()
top_right.x = 5.0
top_right.y = 10.0
rectangle.corner1 = bottom_left
rectangle.corner2 = top_right
dx = 5.0
dy = 12.0
def move_rectangle(rectangle, dx, dy):
"""Takes a rectangle and moves it to the values of dx and dy."""
print ("The rectangle started with bottom left corner at (%g,%g)"
% (rectangle.corner1.x, rectangle.corner1.y)),
print ("and top right corner at (%g,%g)."
% (rectangle.corner2.x, rectangle.corner2.y)),
print ("dx is %g and dy is %g" %(dx, dy))
# print("dx is "+dx+" dy is "+dy)
rectangle.corner1.x = rectangle.corner1.x + dx
rectangle.corner2.x = rectangle.corner2.x + dx
rectangle.corner1.y = rectangle.corner1.y + dy
rectangle.corner2.y = rectangle.corner2.y + dy
print ("It ended with a bottom left corner at (%g,%g)"
% (rectangle.corner1.x, rectangle.corner1.y)),
print ("and a top right corner at (%g,%g)"
% (rectangle.corner2.x, rectangle.corner2.y))
move_rectangle(rectangle, dx, dy)