Python: inheritance. Adding delta_x and delta_y to the 'Shape' class. Note that all other classes inherit from the shape class in this problem. It is the sixth function down. Instructions are on the right side of the screen. My code doesn't work so feel help please.
This code would work. Read and understand it it's pretty simple.
class Shape(object):
def __init__(self, x, y):
self.x = x
self.y = y
class Square(Shape):
def __init__(self, side=1, x=0, y=0):
super(Square,self).__init__(x, y)
self.side = side
class Circle(Shape):
def __init__(self, rad=1, x=0, y=0):
super(Circle,self).__init__(x, y)
self.radius = rad
Now defining the method : as delta
def delta(self, delta_x, delta_y):
self.x += delta_x
self.y += delta_y
Adding this to Shape class:
@add_method(Shape)
def delta(self, delta_x, delta_y):
self.x += delta_x
self.y += delta_y
Get Answers For Free
Most questions answered within 1 hours.