1
00:00:00,000 --> 00:00:03,433
Hi guys, and welcome back. In this video, we're going to solve

2
00:00:03,433 --> 00:00:07,433
the "functions" coding exercise. Let's get started!

3
00:00:07,433 --> 00:00:11,433
The exercise suggests that we have to complete a function called

4
00:00:11,433 --> 00:00:15,433
return_42, by making it actually return 42.

5
00:00:15,433 --> 00:00:18,066
If you look at the code, you can see that at the moment,

6
00:00:18,066 --> 00:00:22,066
the function return_42 is defined, but it doesn't do anything,

7
00:00:22,066 --> 00:00:25,532
it just has "pass", which means "do nothing" in Python.

8
00:00:25,533 --> 00:00:27,699
So we're going to delete that

9
00:00:27,700 --> 00:00:30,433
and then we're going to return 42 here.

10
00:00:30,433 --> 00:00:34,433
Remember that in order to complete the function successfully, you have

11
00:00:34,433 --> 00:00:37,933
to put 4 spaces, well, at least 2 spaces,

12
00:00:37,933 --> 00:00:42,199
but normally we put 4 spaces, in front of the third line.

13
00:00:42,200 --> 00:00:43,700
underneath the colon.

14
00:00:43,700 --> 00:00:47,366
So here we will type, "return 42".

15
00:00:47,366 --> 00:00:51,366
Notice that the function is called return_42

16
00:00:51,366 --> 00:00:54,232
but if you want it to actually return the value 42

17
00:00:54,233 --> 00:00:57,899
you just have to type the word "return", then a space, and then 42.

18
00:00:57,900 --> 00:01:01,033
You don't need any brackets or anything like that.

19
00:01:01,033 --> 00:01:06,066
Next up we have to create a function, which must be called "my_function"

20
00:01:06,066 --> 00:01:09,066
and it has to take two arguments, and return the result

21
00:01:09,066 --> 00:01:11,732
of the two arguments multiplied together.

22
00:01:11,733 --> 00:01:14,833
So, we're going to start by defining the function,

23
00:01:14,833 --> 00:01:18,066
we're going to type "def", and then "my_function"

24
00:01:18,066 --> 00:01:21,599
Then, the opening and closing brackets, and the colon.

25
00:01:21,600 --> 00:01:25,100
Now, because it takes two arguments, it needs two parameters:

26
00:01:25,100 --> 00:01:28,366
one for each argument, so here we're going to put two parameters.

27
00:01:28,366 --> 00:01:32,632
It doesn't matter what you call them, so we're going to type "arg1" and "arg2".

28
00:01:32,633 --> 00:01:36,633
They're comma-separated, and you don't need any quotation marks or anything around these

29
00:01:36,633 --> 00:01:40,633
these are going to be new variables that are created when the function is ran.

30
00:01:40,633 --> 00:01:44,633
So, there are our two parameters, and when we call this

31
00:01:44,633 --> 00:01:49,433
function with two arguments, their values will go into these variables.

32
00:01:49,433 --> 00:01:52,633
And you have to return the result of multiplying

33
00:01:52,633 --> 00:01:55,099
the two arguments together, so you'll type "return"

34
00:01:55,100 --> 00:01:59,100
and then "arg1 * arg2".

35
00:01:59,100 --> 00:02:02,833
Notice that for these exercises you don't have to actually call the functions

36
00:02:02,833 --> 00:02:06,833
it is the test code that we have written, that checks your code,

37
00:02:06,833 --> 00:02:09,966
that will actually call the functions and run them and make sure they together.

38
00:02:09,966 --> 00:02:13,632
So this is all that we have to do for this exercise, the next step

39
00:02:13,633 --> 00:02:17,033
is to check the solution, and as you can see it is correct,

40
00:02:17,033 --> 00:02:21,033
so then you can press "Continue"

41
00:02:21,033 --> 00:02:25,033
Hope that makes sense, and that this concludes the "Functions" section of

42
00:02:25,033 --> 00:02:26,599
this Python Refresher successfully.

43
00:02:26,600 --> 00:02:30,366
Thanks for joining me in this video, and I'll see you in the next one.

