2
class GeometricObject:
    def __init__(self,color = 'green',filled='true'):
        self.__color=color
        self.__filled=filled
    def getColor(self):
        return self.__color
    def setColor(self,color):
        self.__color=color
    def isFilled(self):
        return self.__filled
    def setFilled(self,filled):
        self.__filled=filled
    def __str__(self):
        return "Color: " + self.__color + " Filled: " + str(self.__filled)

And this is the Triangle class:

   from GeometricObject import GeometricObject

   class Triangle(GeometricObject):
       def __int__(self,side1=1.0,side2=1.0,side3=1.0):
           super().__init__()
           self.__side1=side1
           self.__side2=side2
           self.__side3=side3

       def getPerimeter(self):
           return self.__side1 + self.__side2 + self.__side3

       def __str__(self):
           return super().__str__()+" side 1: "+str(self.__side1)+" side 2: "+str(self.__side2)+" side 3: "+str(self.__side3) 

       from triangle import Triangle
       from GeometricObject import GeometricObject

       def main():
           side1=int(input("Enter first side: "))
           side2=int(input("Enter second side: "))
           side3=int(input("Enter third side: "))
           t1=Triangle(side1,side2,side3)
           print(t1.getColor())
           print(t1.getPerimeter())
           print(t1.__str__())
       main()

The error is occuring when I create the triangle object t1 in the main function: init() takes from 1 to 3 positional arguments but 4 were given...

I know there is other posts on similar errors like this but a lot of them were if you provided not enough arguments and the one's that did provide too many arguments did not answer my question.

tyteen4a03
  • 1,812
  • 24
  • 45
Hugh Craig
  • 129
  • 3
  • 3
  • 9
  • possible duplicate of [TypeError: \_\_init\_\_() takes exactly 1 argument (3 given) pyXML](http://stackoverflow.com/questions/11905148/typeerror-init-takes-exactly-1-argument-3-given-pyxml) – johnsyweb Nov 26 '13 at 05:57

2 Answers2

5

You need to change __int__ to __init__, and only pass super() self.

class Triangle(GeometricObject):
       def __init__(self,side1=1.0,side2=1.0,side3=1.0):
           #The correct alternative to below is: 
           #super(GeometricObject, self).__init__()

           GeometricObject.__init__(self) 
           self.__side1=side1
           self.__side2=side2
           self.__side3=side3

To answer your second question, here's an example:

class A(object):
    def __init__(self, color = 'blue'):
        self.color = color

    def __str__(self):
        return str(self.color)

class B(A):
    def __init__(self, name = 'steve'):
        A.__init__(self)    
        self.name = name

    def __str__(self):
        #alternatively: return super(B, self).__str__() + " " + str(self.name) 
        return A.__str__(self) + " " + str(self.name)

prints "blue steve"

Steve P.
  • 14,489
  • 8
  • 42
  • 72
  • That didn't seem to work. So the only change was super().__init__(self)? In the example we did in class we didn't have to provide that self parameter that's why I'm getting confused. – Hugh Craig Nov 26 '13 at 05:56
  • You also need to change `__int__` to `__init__`. Again, I would also use `GeometricObject.__init__(self)`, but that shouldn't matter. – Steve P. Nov 26 '13 at 05:57
  • :P I did not see that. Thankyou my eyes aren't catching these things after frustration.. – Hugh Craig Nov 26 '13 at 05:59
  • 1
    @HughCraig I made a few updates for clarification... If you feel that I've answered your question, would you please accept my answer? – Steve P. Nov 26 '13 at 17:11
1

Triangle's init function is misspelled as __int__ :
def __int__(self,side1=1.0,side2=1.0,side3=1.0):

change to:
def __init__(self,side1=1.0,side2=1.0,side3=1.0):

Works for me!

Juan Carlos Moreno
  • 2,754
  • 3
  • 22
  • 21
vfxdrummer
  • 436
  • 4
  • 7
  • Hey I got that part now. But I also just got an error which doesn't make sense because I did it in my last program and now it's not letting me this part: 'code'return super().__str__()+" side 1: "+str(self.__side1)+" side 2: "+str(self.__side2)+" side 3: "+str(self.__side3)'code' It gives me this error: Can't convert 'Triangle' object to str implicitly – Hugh Craig Nov 26 '13 at 06:02