0

I have the code:

class Triangle(Coordinate):
    def __init__(self,xcoord,ycoord,color):
        self.color = color
        super().__init__(xcoord,ycoord)

(inheriting from class Coordinate) And whenever I call it, for example

t1 = Triangle(Coordinate(1,1), Coordinate(2,1), Red)

It only returns the coordinates, how do it make it return the color as well?

Brent Washburne
  • 12,904
  • 4
  • 60
  • 82
genieSessions
  • 29
  • 1
  • 1
  • 9

1 Answers1

0

The answer has been posted in the comments but I think you misunderstood him, so I am going to elaborate a bit more.

Your class Triangle inherits functions from a parents class of some sort. Even though you didn't write a def __str__(self): in Triangle, it can still be used because it is defined in your parent class, and Triangle inherits functions from the parent class

If you don't want to use any of the parent class' functions, you can redefine it in Triangle. When you call that function on a Triangle Python will prefer to use the def __str__(self): in Triangle before referencing the parent class.

In short, you need to write a new def __str__(self): similar to the one in your parent class, but add another portion in the output that accounts for the color. I hope this helps Charmaine. Good luck!

mmghu
  • 595
  • 4
  • 15