Build a Polygon Area Calculator - Build a Polygon Area Calculator

Tell us what’s happening:

No idea why im failing tests about ‘different string representation’ because it literally is different.

Your code so far

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

    @property
    def set_width(self):
        return self.width

    @set_width.setter
    def set_width(self, value):
        self.width = value

    @property
    def set_height(self):
        return self.height

    @set_height.setter
    def set_height(self, value):
        self.height = value

    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) ** 0.5

    def get_picture(self):

        pic = ""
        if self.width > 50 or self.height > 50:
            return "Too big for picture."
        else:
            for i in range(self.height):
                pic += "*" * self.width + "\n"

        return pic.strip()

    def get_amount_inside(self, shape):
        return (self.width // shape.width) * (self.height // shape.height)

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

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

    @property
    def set_width(self):
        return self.width

    @set_width.setter
    def set_width(self, value):
        self.width = value
        self.height = value

    @property
    def set_height(self):
        return self.height

    @set_height.setter
    def set_height(self, value):
        self.width = value
        self.height = value

    @property
    def set_side(self):
        return self.width

    @set_side.setter
    def set_side(self, value):
        self.set_width = value
        self.set_height = value


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

s = Square(5)
print(s)
print(s.get_picture())
s.set_side = 4
print(s)
print(s.get_picture())

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:156.0) Gecko/20100101 Firefox/156.0

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

Welcome to the forum @the-ramu-dev,

If I test with the code in the instructions:

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))

I see an error in the console:

50
Traceback (most recent call last):
  File "main.py", line 85, in <module>
TypeError: 'int' object is not callable

Where were you asked to create getters and setters in this challenge?

Happy coing

Hi @the-ramu-dev

from my observation, the implementation does not requires you creating getter and setters for updating the data attribute. the user stories explicitly stated that you should create methods

Here for instance
rect.set_height(3)
test will fail because you are using getter and setters which work only if the update test is rect.set_height = 3

so you need to remove all the getter and setter and use normal method to update the attributes

Happy Coding!!!