For this challenge we are going to use a Python script to calculate the area in square meters of two different flats.
To do so we will write a computer program that will add up all the areas of each room.
Most rooms have a rectangle shape. So we will first define a function that takes two parameters: width and length and return the area of the rectangle using the following formula:
Let’s use this formula to calculate the area of this small flat:
Tweak the code above to calculate the area of the following two flats: (Click on each picture to zoom in).
The area of a right-angled triangle can be calculated as follows:
Add a new function called getTriangleArea to return the area of a right-angled triangle using two parameters: width and length.
Use both the getRectangleArea and getTriangleArea functions to calculate the area of this room:
Use your code to calculate the area of this small mansion (Click on picture to zoom in):
Solution...The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area