Build a Polygon Area Calculator - Build a Polygon Area Calculator

Tell us what’s happening:

I am getting “Your code raised an error before any tests could run…” when running the tests but it works inside of the development environment just fine. Where am i mistaken?

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 width

    def set_height(self, height):
        self.height = height
        return height
    
    def get_area(self):
        return self.width * self.height

    def get_perimeter(self):  
        return 2 * (self.width + self.height)

    def get_diagonal(self):
        return ((self.width ** 2) + (self.height ** 2)) ** (1 / 2)

    def get_picture(self):
        rectstring = ''
        if self.width > 50 or self.height > 50:
            rectstring = 'Too big for picture.'
            return rectstring
        else:
            for i in range(self.height):
                for j in range(self.width):
                    rectstring += "*"
                rectstring += "\n"
            return rectstring
    
    def get_amount_inside(self, viereck: Rectangle):
        if self.width < viereck.width or self.height < viereck.height:
            return 0
        else:
            return (self.width // viereck.width) * (self.height // viereck.height)
    
    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, side):
        super().set_width(side)
        super().set_height(side)
        self.side = side
        return side

    def set_height(self, side):
        return self.set_width(side)

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

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

Your browser information:

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

Challenge Information:

Build a Polygon Area Calculator - Build a Polygon Area Calculator

try to write rect = Rectangle(2, 4), you will see the error

still no error in terminal or IDE.

you do not see this error?

Traceback (most recent call last):
  File "main.py", line 1, in <module>
  File "main.py", line 35, in Rectangle
NameError: name 'Rectangle' is not defined

maybe share again your code, there could be some differences

Traceback (most recent call last):
File “main.py”, line 1, in
File “main.py”, line 35, in Rectangle
NameError: name ‘Rectangle’ is not defined

I also get that error message from your code, i think you should take a closer look at line 35, where ‘: Rectangle’ is not defined, I made your code work by just changing the parameters ! hope it helps

i got a traceback in a different browser now. Solved. Thank you

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