Polygon Area Calculator

JSaw
2 min readOct 23, 2021

--

Project 1 of 5 freeCodeCamp’s Scientific Computing with Python

After going through the initial lessons in Scientific Computing with Python at freeCodeCamp, although I could vaguely know what kind of methods I should use, I do not exactly remember the functions I need to use, something like when I would sometimes still need to rely on the prompts by Excel formula box to type out my formulas.

To help me with my projects, I use my usual method, Googling on the materials regarding Python itself. So sharing here the materials I have went through to complete my projects.

Starting with the project : Polygon Area Calculator

Creating objects with methods inside

This project involves creating two classes Rectangle and Square, with methods in it.

Object inheritance

Square is subclass of Rectangle, so we would need to understand what class inheritance is.

Understand what does “**” mean

For the get_diagonal method, we will be using the “**” operator. This operator is for “power of”, i.e exponentian

Creating new line using “\n” to create shapes using “*”

For the get_picture method, we will need to create a string that uses lines of “*” to represent the shape of the object.

For that, we will need to create lines of “*” within the string itself. To create new lines in a string, we will need the “\n” character in the string.

To set the string that an object returns when the object is called

When you want an object to return a sentence when it is called upon, we can use the __str__(self)method.

This __str__(self) method will set the string representation of the class. With this method, we can just use Print() to call the object to show the string set.

Links to my other project articles in this Scientific Computing with Python series

--

--