| tutorial | https://www.youtube.com/watch?v=8tvkCp3EMiM |
|---|
A function could receive zero parameters, and it always returns something, even if you don't explicitly add the return statement.
👉 Click here to read more about functions.
For example: a function that calculates the area of a square will be something like this:
def calculate_area(length, width):
return length * widthIf you want to use that function to calculate the area of a square with:
length = 3
width = 6You need to do something like this:
area = calculate_area(3,6)
# The value of 'area' will be set to 18- Create new variables named
square_area1,square_area2,square_area3and call the functioncalculate_areathree times, one for each square in the picture, for example:
# For the first figure:
square_area1 = calculate_area(4,4)-
Call the
calculate_areafunction three times, one per each square, passing the length and edge of each square.
