WEBVTT

00:00.080 --> 00:06.230
This is the solution for the activity number one, where you have to concatenate two strings and also

00:06.230 --> 00:07.790
put them uppercase.

00:07.790 --> 00:11.630
So first of all, if you manage to do the activity on your own, congratulations.

00:11.630 --> 00:14.540
And if you didn't manage to finish it well, it's okay.

00:14.570 --> 00:15.620
Don't worry too much.

00:15.800 --> 00:20.690
You can watch the solution and then you can go back to watch the concepts again and try it again, and

00:20.690 --> 00:22.400
maybe try again in a few days.

00:22.400 --> 00:26.660
And just practice until this activity becomes easy enough for you.

00:26.690 --> 00:27.140
All right.

00:27.140 --> 00:32.030
So I will remove all of that and let's create a function.

00:32.030 --> 00:35.450
So def how do we name our function.

00:35.450 --> 00:39.470
Well we want to concatenate strings and actually uppercase strings.

00:39.470 --> 00:48.710
So concatenate concatenate uppercase strings and I open the parentheses.

00:48.710 --> 00:52.850
You can see this name starts to be a bit long but it's still not that long okay.

00:52.880 --> 00:56.360
So as best practice is better to have short names.

00:56.360 --> 01:01.330
But even more important than that, it's better to have names that are meaningful.

01:01.360 --> 01:01.810
Okay.

01:01.810 --> 01:04.030
So here it's pretty explicit.

01:04.060 --> 01:06.760
So in the parentheses I'm going to add parameters.

01:06.760 --> 01:08.380
How many strings do I have.

01:08.380 --> 01:10.270
Well here I'm going to use two strings.

01:10.270 --> 01:16.780
I'm just going to name them str underscore a and str underscore b.

01:16.810 --> 01:17.170
Okay.

01:17.200 --> 01:20.350
Since we are only going to use that inside this function okay.

01:20.380 --> 01:23.590
And this is a local variable I can just use this name.

01:23.590 --> 01:24.820
It's not going to be a problem.

01:24.820 --> 01:31.210
So I close the parentheses I put a colon I go back to a new line with an indentation of four spaces

01:31.210 --> 01:31.570
here.

01:31.570 --> 01:34.300
And then let's do result.

01:34.330 --> 01:35.860
What will be the result.

01:35.860 --> 01:41.620
So we want to do str a plus str b.

01:41.680 --> 01:45.040
This will concatenate the two strings.

01:45.070 --> 01:48.910
But I also need to add a space in between okay.

01:48.940 --> 01:50.860
So I'm going to add a space.

01:50.860 --> 01:53.740
So we'll simply a quote like this with a space.

01:53.740 --> 02:01.080
And then plus okay so I can do plus between two strings, but also between three strings.

02:01.080 --> 02:03.420
I can add as many strings as I want.

02:03.450 --> 02:05.610
So here I'm adding three strings.

02:05.610 --> 02:12.180
This one that we get in a parameter, and then an empty character, and then the second string that

02:12.180 --> 02:14.880
will concatenate the two strings with a space.

02:14.880 --> 02:17.610
But we still need to put them uppercase.

02:17.610 --> 02:19.950
So I will do the first.

02:20.040 --> 02:24.900
So string a dot upper like this and open close parenthesis.

02:24.930 --> 02:29.220
And the same thing for the strb upper.

02:30.120 --> 02:37.020
This way we are going to first put the string a in uppercase, add a space and then the string B in

02:37.050 --> 02:37.860
uppercase.

02:37.860 --> 02:40.620
Let's save this file as.

02:40.620 --> 02:48.030
So save or save as and let's name it activity one dot p y.

02:48.900 --> 02:49.140
Okay.

02:49.170 --> 02:52.740
So I'm going to follow the same template for all activities.

02:52.740 --> 02:59.210
And then you can also download the code for each activity if you want to Click on okay.

02:59.210 --> 03:02.150
So it is saved.

03:02.150 --> 03:05.840
And then well if I run it the thing is you can see nothing happens.

03:05.840 --> 03:06.290
Why?

03:06.320 --> 03:11.150
Because we have defined a function but we don't use this function.

03:11.150 --> 03:13.700
And actually we don't even use this function.

03:13.700 --> 03:16.730
But we don't even return anything from the function.

03:16.730 --> 03:18.830
So I can do return result.

03:18.860 --> 03:19.400
Okay.

03:19.430 --> 03:26.000
Because if I just create the function like this, what is it going to compute the concatenation and

03:26.000 --> 03:27.530
put it inside the result variable.

03:27.530 --> 03:31.250
But if we don't return it well we're going to lose this result.

03:31.280 --> 03:34.790
But still it's not going to do anything because we don't call it.

03:34.790 --> 03:37.790
So I'm going to go back to a new line.

03:37.790 --> 03:41.960
And you can see it's important to go back to a new line with zero indentation here.

03:41.960 --> 03:44.780
If I do this we are still in the function okay.

03:44.810 --> 03:50.000
So I go here and I will do print concatenate concatenate.

03:50.000 --> 03:58.610
So here I'm going to use also the autocompletion I'm going to use Ctrl space and then tab or enter.

03:58.610 --> 04:01.070
So concatenate uppercase string.

04:01.070 --> 04:03.290
I'm going to say the first string is hello.

04:04.100 --> 04:04.760
Like this.

04:04.790 --> 04:07.970
And then a comma and then world.

04:08.030 --> 04:13.280
And then I close the parentheses and I need to close the parenthesis twice okay.

04:13.760 --> 04:17.990
One for this function and also one for the print function.

04:18.020 --> 04:20.210
Let's let's run it.

04:20.270 --> 04:22.580
And you can see we have the correct result.

04:22.610 --> 04:26.150
Hello world with a space and all uppercase.

04:26.180 --> 04:31.220
Now let's say for example if you have only one parameter.

04:31.220 --> 04:33.830
So let's say you don't give the correct amount of parameters.

04:33.830 --> 04:36.800
So here you give two few parameters.

04:36.800 --> 04:38.060
Let's see what happens.

04:38.540 --> 04:44.900
You have an error of course that says missing one required argument okay.

04:44.930 --> 04:50.510
So you need to provide exactly the same amount of parameters that you have in the function.

04:50.510 --> 04:53.240
So if you have two here it's going to be two here.

04:53.240 --> 04:55.630
If you have three you need to provide three Etc..

04:55.630 --> 05:00.760
And look, what we can also do is because this is going to return a string, we need to pass a string

05:00.760 --> 05:01.570
as a parameter.

05:01.570 --> 05:06.010
So I can also call concatenate uppercase string here.

05:06.010 --> 05:07.690
So let's do concatenate.

05:08.110 --> 05:11.860
I'm going to use Ctrl and space again.

05:11.860 --> 05:16.480
And let's put world like that okay.

05:16.480 --> 05:17.800
And close the parenthesis.

05:17.800 --> 05:26.170
So basically what we do is we first concatenate some strings and actually not just world but hello and

05:26.170 --> 05:26.410
world.

05:26.410 --> 05:27.760
We need to pass two parameters.

05:27.760 --> 05:32.860
So we are going to call that first it's going to give us Hello world all uppercase.

05:32.860 --> 05:37.180
And then we're going to use the result as an input parameter for this function.

05:37.180 --> 05:40.090
So the same function again with hello.

05:40.090 --> 05:41.770
And then the result of that.

05:41.770 --> 05:44.860
And finally we print the whole thing okay.

05:44.860 --> 05:48.100
You can see you can really go far when combining functions.

05:48.100 --> 05:51.730
And make sure you can see that you close three parentheses okay.

05:51.760 --> 05:53.230
Let's see what happens.

05:53.890 --> 06:00.000
And now we have hello, Hello world because this one is going to give us Hello world.

06:00.030 --> 06:01.560
And then we add another hello.

06:01.560 --> 06:03.240
So hello, hello world.

06:03.240 --> 06:06.060
And just to finish here with optimization.

06:06.060 --> 06:08.790
Well again you can see we create a variable.

06:08.790 --> 06:10.410
We just return this variable.

06:10.410 --> 06:13.860
And this what anyway is created inside this function.

06:13.860 --> 06:18.420
We are not going to use it outside because it's only available in this scope.

06:18.420 --> 06:25.110
So if you just create a variable that you return immediately after that, you probably don't need the

06:25.110 --> 06:26.220
variable anyway.

06:26.220 --> 06:33.000
So instead of doing this, I'm just going to return the result and of course remove that line.

06:33.510 --> 06:36.030
So now we return directly the result.

06:36.060 --> 06:37.680
It's going to give us the same thing.

06:37.680 --> 06:38.130
Great.

06:38.130 --> 06:40.650
And that's the end of this first activity.

06:40.650 --> 06:44.310
So if it was too hard once again come back to the previous lessons.

06:44.310 --> 06:48.120
Try to do the activity again today, maybe another day okay.

06:48.150 --> 06:49.860
Give it some time, some practice.

06:49.860 --> 06:53.970
And at some point you will see you will manage to do it without any effort.
