Build a Polygon Area Calculator - Build a Polygon Area Calculator

Tell us what’s happening:

I can’t seem to understand the reason why I have an 18th error. I was hoping if anyone could help shed light on the error for me.

Your code so far

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

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

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

    def get_area(self) -> int:
        area = self.width * self.height
        return area
    
    def get_perimeter(self) -> int:
        perimeter = self.width + self.height
        perimeter *= 2
        return perimeter

    def get_diagonal(self) -> float :
        diagonal = (self.width ** 2 + self.height ** 2) ** 0.5
        return diagonal

    def get_picture(self) -> str:
        if self.width > 50 or self.height > 50:
            return 'Too big for picture.'
        symbol = '*'
        result = '' 
        for i in range(0, self.height):
            result += f"{symbol * self.width}\n"

        return result

    def get_amount_inside(self, shape) -> int:
        return self.get_area() // shape.get_area()

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

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

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

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

    def set_side(self,side):
        self.side = side
        return self.side

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


    

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36

Challenge Information:

Build a Polygon Area Calculator - Build a Polygon Area Calculator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-polygon-area-calculator/5e444147903586ffb414c94f.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @Fireeditor_360

To help you debug, add the following code in the editor and compare the shape of the square in the console to the expected shape.

rect = Rectangle(10, 5)
print(rect.get_area())
rect.set_height(3)
print(rect.get_perimeter())
print(rect)
print(rect.get_picture())

sq = Square(9)
print(sq.get_area())
sq.set_side(4)
print(sq.get_diagonal())
print(sq)
print(sq.get_picture())

rect.set_height(8)
rect.set_width(16)
print(rect.get_amount_inside(sq))

Happy coding

I think it will be easier to see what’s wrong if you just use the code for the Square that @Teller provided. You’ll be able to easily see that the “picture” your code creates is not square.