|
2 | 2 | tutorial: "https://www.youtube.com/watch?v=NU5iW_bWwmY"
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -# `04` Calling a function |
| 5 | +# `04` Calling a Function |
6 | 6 |
|
7 | 7 | A function could receive zero parameters, and it always returns something, even if you don't explicitly add the `return` statement.
|
8 | 8 |
|
9 |
| -:point_up: [Click here to read more about functions](https://content.breatheco.de/lesson/working-with-functions-python) |
| 9 | +👉 [Click here to read more about functions](https://content.breatheco.de/lesson/working-with-functions-python) |
10 | 10 |
|
11 | 11 | For example: a function that calculates the area of a square will be something like this:
|
12 | 12 |
|
13 | 13 | ```python
|
14 |
| -def calculate_area(length, edge): |
15 |
| - return length * edge |
| 14 | +def calculate_area(length, width): |
| 15 | + return length * width |
16 | 16 | ```
|
17 | 17 |
|
18 | 18 | If you want to use that function to calculate the area of a square with:
|
19 | 19 |
|
20 | 20 | ```python
|
21 | 21 | length = 3
|
22 |
| -edge = 6 |
| 22 | +width = 6 |
23 | 23 | ```
|
24 | 24 |
|
25 | 25 | You need to do something like this:
|
26 | 26 |
|
27 | 27 | ```python
|
28 | 28 | area = calculate_area(3,6)
|
29 |
| -# The value of area will be set to 18 |
| 29 | +# The value of 'area' will be set to 18 |
30 | 30 | ```
|
31 | 31 |
|
32 | 32 | ## 📝 Instructions:
|
33 | 33 |
|
34 |
| -1. Create a new variables named `square_area1`, `square_area2`, `square_area3` and call the function `calculate_area` three times one for each square in the picture, for example: |
| 34 | +1. Create new variables named `square_area1`, `square_area2`, `square_area3` and call the function `calculate_area` three times, one for each square in the picture, for example: |
35 | 35 |
|
36 | 36 | ```python
|
37 | 37 | # For the first figure:
|
38 | 38 | square_area1 = calculate_area(4,4)
|
39 | 39 | ```
|
40 | 40 |
|
41 |
| - |
| 41 | + |
42 | 42 |
|
43 |
| -## 💡 Hint: |
| 43 | +## 💡 Hints: |
44 | 44 |
|
45 | 45 | + Call the `calculate_area` function three times, one per each square, passing the length and edge of each square.
|
46 | 46 |
|
47 |
| -+ :video_camera: [9 min video about functions in python](https://www.youtube.com/watch?v=NE97ylAnrz4) |
| 47 | ++ 📹 [9 min video about functions in Python](https://www.youtube.com/watch?v=NE97ylAnrz4). |
48 | 48 |
|
0 commit comments