Final Exam Review Spring 2006: Working with classes
Questions? Post them here.
would this work for b.)?
class Box:
def __init__(self):
self.setDefaultColor()
self.size=10
self.position=(10,10)
self.setColor()
def setDefaultColor(self):
self.color = red
def draw(self,canvas):
addRectFilled(canvas,self.position[0],self.position[1],self.size,self.size,self.color)
def setColor(self):
self.color = blue
| No. Check your setColor function. It needs to take in a generic color, not just blue. -poof #10 |
c)
class Box:
def __init__(self):
self.setDefaultColor()
self.size=10
self.position=(10,10)
def setDefaultColor(self):
self.color = red
def draw(self,canvas):
addRectFilled(canvas,self.position[0],self.position[1],self.size,self.size,self.color)
def grow(self, size)
self.size = self.size + size
| You only need to set self.size to what you pass in. After you call grow, you have to recall draw, and draw will grab the size for both the width and height.-poof #10 |
i am totally confused about this question – can i get a hint as to where to start. thanks!
page 325 off the textbook
when the default color is already set to red, how can you change it without actually removing "red" from the code?
| You don't remove the default color. You create a function to change it.-poof #10 |
(a)
a red box 10 pixels long at (10,10) against a white background of size (400,200)
| Black background. makeEmptyPicture makes a completely black backgroung.-poof #10 |
(b)
def setColor(self, input):
self.color = input
(c)
def setSize(self, input):
self.size = input
(d)
def setPosition(self, input):
self.position = (input[0], input[1])
(e)
a box like in (a) but it will be blue instead of red.
yea?
Link to this Page