Scientific Computing with Python Projects - Polygon Area Calculator

hello I have one error as you can see but I dont know whats going on. Although I think i havent covered some of the corner cases but it asses mosto f tests.

Also big question in def get_amount_inside () function. Why wasnt it working when i was passing instance and then calling self._side , it was giving me completely different result, i was printing it out and it was giving me that self._side = 5. So i had to call sq._side or in this case because wasnt passing test instance._side. What did happen there so it was giving me side = 5 instead of 4

Also I have question

Your code so far

Your browser information:

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

Challenge Information:

Scientific Computing with Python Projects - Polygon Area Calculator

There’s no Run button here, so your error isn’t visible. In the future you could copy and paste the error here for review. (Your error would get looked at sooner).

Here is the error:

'Expected string representation of square after setting width to be "Square(side=4)"')
AssertionError: 'Square(side=2)' != 'Square(side=4)'
- Square(side=2)
?             ^
+ Square(side=4)
?             ^

So the test executes


But the square returns 2, not 4.

I think this is related to the instruction here:

Additionally, the set_width and set_height methods on the Square class should set both the width and height.

1 Like

Thanks a lot, now its working. But this question still remains. In get_amount_inside method i couldnt use self._side but rather i had to use instance._side (the value i was passing which was actually a class) and then was giving correct output

You can’t use class because you are passing another instance of the class, (another object, another shape). So there are 2 shapes, self and the other one). You can only refer to one of them as self. You’ve assigned the other shape to instance when defining the function:

def get_amount_inside(self,instance):

get_amount_inside: Takes another shape (square or rectangle) as an argument. Returns the number of times the passed in shape could fit inside the shape (with no rotations). For instance, a rectangle with a width of 4 and a height of 8 could fit in two squares with sides of 4.