Exercise 08-03:

Write a function that takes the length of the side of a square and returns its area (A = side2).

Expected values:

square_area(4) == 16

square_area(9) == 81

Answer:

##############################################################################
# Python From Scratch
# Author: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2025 - LogiKraft 2025
# Site: https://pythonfromscratch.com
# ISBN: 978-85-7522-949-1 (Paperback), 978-85-7522-950-7 (hardcover), 978-85-7522-951-4 (ebook)
#
# File: chapter 08/exercise-08-03.py.py
##############################################################################
def square_area(side):
    return side**2


print(f"square_area(4) == 16 -> obtained: {square_area(4)}")
print(f"square_area(9) == 81 -> obtained: {square_area(9)}")
Click here to download the file