freeCodeCamp/CurriculumExpansion

Polygon Area Calculator (Certification Project)

Closed this issue ยท 17 comments

Create project from the Python scientific computing certification.

Hi,

I've finished this challenge and I've seen one thing that is not clear on the readme.md. When you say:

get_diagonal: Returns diagonal (((width 2 + height 2) ** .5)

it should be:

get_diagonal: Returns diagonal (((width**2 + height**2) ** .5)

Completed project: https://repl.it/repls/CrookedGiddyVertex

Everything was clear for me, thanks for the project. The only issue I encountered is typo in tests: when the string representation checked it asks for heigh instead of height.

 def test_rectangle_string(self):
        actual = str(self.rect)
        expected = "Rectangle(width=3, heigh=6)"
        self.assertEqual(actual, expected, 'Expected string representation of rectangle to 		 
        be "Rectangle(width=3, heigh=6)"')

Completed the project too; https://repl.it/@borntofrappe/fcc-shape-calculator

The README has also a couple of typos:

  • The word height is misspelled as hight. This happens in both paragraphs introducing the classes.

  • In the paragraph introducing the square class, the word length is misspelled as legth.

get_diagonal: Returns diagonal (((width 2 + height 2) ** .5)

it should be:

get_diagonal: Returns diagonal (((width**2 + height**2) ** .5)

The square operator is actually included in the markdown, but is not rendered proprerly by the previewer. This is fixed by wrapping the markdown syntax in backticks.

`(((width ** 2 + height ** 2) ** .5)`

For the expression itself, I believe the number of parenthesis is off by one.

- (((width**2 + height**2) ** .5)
+ ((width**2 + height**2) ** .5)

@borntofrappe, great catch. The typo and the extra opening parenthesis are both things we'll fix in the next draft.

Thanks for the suggestions everybody. I made the fixes.

other than spelling, good little problem. Was fun.

Thanks for the project ๐Ÿ˜ƒ

There is a typo in the test_module.py line 66
"Rectangle(width=7, heigh=8)" should be "Rectangle(width=7, height=8)"

@adamdune Fixed, thanks.

my solution: https://repl.it/@MaikRo/fcc-shape-calculator

I have one logic question - The square has a set_width and set_height method which was inherited from the parent class, however the functionality should be different for a square, no?
Right now there is no mention in the readme that this logic needs to be adjusted as well in order to make a proper 'square', should this be added?

@lefthand3r, that's a good point. I don't think it's strictly necessary given the solution here, but definitely worth considering since those methods will be inherited from Rectangle. I suspect that a lot of people will think along the same lines.

@lefthand3r That is a good point. I added the line below to the instructions and also added a test for this. Do you think this is a good way to address the issue you brought up.

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

Liked doing this project. Particularly found it easier after doing budget app project. I found no mistakes but would recommend to make the projects a bit harder and the steps to do this was mentioned in detailed way which is not true in actual sense. My two cents. Thanks for these projects :)

Link : https://repl.it/@ManshulArora/shape-calculator#shape_calculator.py

I revisited the project at the new URL, and found a potential issue with one of the tests.

The issue is with the Square class and the test test_set_atributes: since the test updates the width of the shape with set_width, it's enough to have the __str__ method use the width to have the test succeed.

def __str__(self):
  return 'Square(side=' + str(self.width) + ')'

In this instance, there's no guarantee that the width and height match. In other words, if you don't update the set_width and set_height methods to have the attributes change together, the test succeeds still.

I don't know if I've expressed myself clearly enough, so I'll link to my solution for added context:

https://repl.it/@borntofrappe/fcc-shape-calculator#shape_calculator.py


Update: I've realized it would be much more clear to just add the snippet that works, but shouldn't. Apologies for the convoluted report, and let me know if you need more details.

class Square(Rectangle):
    def __str__(self):
        w = str(self.width)
        return 'Square(side=' + w + ')'

    def __init__(self, side):
        super().__init__(side, side)

    def set_side(self, side):
        self.width = side
        self.height = side

I've a couple of additional notes with regards to the starter project.

README.md

The instructions are very clear. The only suggestion I have is for the paragraphs describing how the shapes are represented as a string.

Instead of using hard-coded values:

Additionally, if an instance of a Rectangle is represented as a string, it should look like: Rectangle(width=5, height=10)

I would specify the format as follows:

Additionally, if an instance of the Rectangle class is represented as a string, it should look like: Rectangle(width=w, height=h), where "w" and "h" refer to the width and height of the object.

Similarly, and for the Square class

If an instance of a Square is represented as a string, it should look like: Square(side=9)

If an instance of a Square is represented as a string, it should look like: Square(side=s), where "s" describes describes the side of the object.

main.py

The script includes a series of methods to show how the project works, but the code seems to refer to the previous version of the project (without the get_picture and get_amount_inside methods).

By far, this is a miniscule issue, but perhaps it's better to include the code already described in the README and in the Usage example section.

rect = shape_calculator.Rectangle(10, 5)
print(rect.get_area())
rect.set_height(3)
print(rect.get_perimeter())
print(rect)
print(rect.get_picture())
 
sq = shape_calculator.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))

Everything seems fine but at line number 73 in test_module.py
self.sq.set_width(4)
actual = str(self.sq)
expected = "Square(side=4)"
self.assertEqual(actual, expected, 'Expected string representation of square after setting width to be "Square(side=4)"')
Why square object calling set_width method . It should be "self.sq.set_side(4)".
Pls take a look at that.