Ok folks...more help with a programming class...
I'm seriously starting to think programming is not for me, but I just want to finish out this class with a decent grade. I'm not looking for answers...just some guidance in the right direction.
Here is the problem...
As an exercise, write a function named moveRect that takes a
Rectangle and two parameters named dx and dy. It should change
the location of the rectangle by adding dx to the x coordinate of corner
and adding dy to the y coordinate of corner.
Here is what I have so far...
class Rectangle: pass class Point: pass box = Rectangle() box.width = 100 box.height = 200 box.corner = Point() box.corner.x = 0.0 box.corner.y = 0.0 def findCenter(box): p = Point() p.x = box.corner.x + box.width/2.0 p.y = box.corner.y - box.height/2.0 return p def printPoint(p): print "(" + str(p.x) + ", " + str(p.y) + ")" center = findCenter(box) printPoint(center) def moveRect(box, dx, dy) : box.corner = Point() box.corner.x = box.corner.x + dx box.corner.y = box.corner.y + dy
When I run it and input variables for dx and dy, it gives me this error:
>>> moveRect(box, 10, 20) Traceback (most recent call last): File "<pyshell#14>", line 1, in <module> moveRect(box, 10, 20) File "C:/Users/Tony/Documents/Module 4 CS/moveRect", line 28, in moveRect box.corner.x = box.corner.x + dx AttributeError: Point instance has no attribute 'x'
Thanks for any help.