Polygon Area Calculator TypeError

Hie guys! I am doing a python project about polygon area calculator. I am having a TypeError when I run it, may you kindly assist with help because I have tried to rectify it but to no avail. https://repl.it/@KayDeeSibbs/boilerplate-polygon-area-calculator#shape_calculator.py. Thanx

here is the error

 python main.py
50
26
Rectangle(width=3), height=10
Traceback (most recent call last):
  File "main.py", line 12, in <module>
    sq = shape_calculator.Square(9)
  File "/home/runner/boilerplate-polygon-area-calculator/shape_calculator.py", line 58, in __init__
    super().__init__(width=side, height=side)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
exit status 1
 

Here is my code so far

class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height

    def __str__(self):
        return f"Rectangle(width={self.width}), height={self.height}"

    def set_width(self, width):
        self.width = width

    def set_height(self, height):
        self.height = height

    def get_area(self):
        width = self.width
        height = self.height

        return width * height

    def get_perimeter(self):
        width = self.width
        height = self.height

        return 2 * width + 2 * height

    def get_diagonal(self):
        width = self.width
        height = self.height

        a = width ** 2
        b = height ** 2

        return (a + b) ** 0.5

    def get_picture(self):
        width = self.width
        height = self.height

        if height < 50 and width < 50:
            a = "*" * self.width
            b = "\n"
            c = self.height
            return (a + b) *c

        else:
            print("Too big for the picture")

        
    def get_amount_inside(self, shape):
        height_times = self.height // shape.height
        width_times = self.width // shape.width
        number_of_times = height_times * width_times
        return number_of_times

class Square:
    def __init__(self, side):
        super().__init__(side, side)

    def __str__(self):
        return f"Square(side={self.width})"

    def set_side(self, side):
        self.width = side
        self.height = side

    def set_width(self, width):
        self.set_side(width)

    def set_height(self, height):
        self.set_side(height)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36.

Challenge: Polygon Area Calculator

Link to the challenge:

placement of parenthesis is wrong here. it should be like this:

return f"Rectangle(width={self.width}, height={self.height})"

Thanx! I did correct that part, but unfortunately the TypeError comes back again when I run it. Would really appreciate more help

Keep in mind that super() is supposed to return class, from which the current class is inheriting. Notice that in error this points to object class, while the parent of Square class should be Rectangle.

Oh ok. So how am I supposed to fix that. Any idea? Because honestly I am stuck

Do you remember how to indicate that class should inherit from another class?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.