Area and perimeter of a rectangle

Last year, the concepts of area and perimeter were introduced to my kid in his math course.

🐍 Today, he asked me to spend some time programming in python.

I proposed to write a program to calculate the area of a rectangle.

🗣️ After a brief discussion, we got our algorithm:

algorithm-rectangle.jpg

Hands-on time❗

print("===== WELCOME =====")
print("Let us calculate the area of a rectangle.")
b = float(input("How long is the base?"))
h = float(input("How tall is the height?"))
print(f"The area of the rectangle is {b*h}")

algorithm-rectangle-code1.png

He was so excited that started asking for more… so, I told him:

Do you remind the concept of perimeter? We can add the calculation of the perimeter with one line.

I wrote the formula in the board (\(P = 2 (b + h)\)), and asked him to think what should by that line.

With a little help he wrote the last line in the following code:

print("===== WELCOME =====")
print("Let us calculate the area of a rectangle.")
b = float(input("How long is the base?"))
h = float(input("How tall is the height?"))
print(f"The area of the rectangle is {b*h}")
print(f"The perimeter of the rectangle is {2*(b+h)}")

algorithm-rectangle-code2.png

Author: Oscar Castillo-Felisola

Created: 2026-04-02 Thu 14:59