Python Project - Polygon Area Calculator

Hello everyone!

I just finished the Polygon Area Calculator project, and also enhanced it a little bit looking at some feedbacks.

The thing is, there’s still something I don’t fully understand. Part of the instructions said that " the set_width and set_height methods on the Square class should set both the width and height."

Does this mean that when calling square_object.set_height or square_object.set_width both attributes should change? Because if that’s the case, the only way I found to achieve it was to repeat the set_height and set_width methods from the superclass, and make both return the set_side method, which changes the width and lenght of the square to the same value:


def set_side(self, new_side):

    self.width = new_side
    self.height = new_side
def set_height(self, new_height):

    return self.set_side(new_height)
def set_width(self, new_width):

    return self.set_side(new_width)

Is there a more efficient way to do this? Or have I just missunderstood the instructions?

Thanks in advance! Here’s the link to my code, in case you wanna check it out:



1 Like

Pretty much that what it means. After all square should stay square, so when height is changed the same change should be applied to the width and the other way around.

In the terms of performance efficiency this won’t change much, but the set_side method could call parent methods to set both height and width instead of doing that on it own. While not cutting down number of lines, it allows to keep the actual change of height and width values in a single place.

Notice also that return is not needed in Square methods set_height and set_width, as set_side is not returning anything explicitly it can be just called normally and it still will be executed as it should.

1 Like

Excellent, then! Thank you so much. This was very useful :+1: