This is the solution for the activity number one, where you have to concatenate two strings and also
put them uppercase.
So first of all, if you manage to do the activity on your own, congratulations.
And if you didn't manage to finish it well, it's okay.
Don't worry too much.
You can watch the solution and then you can go back to watch the concepts again and try it again, and
maybe try again in a few days.
And just practice until this activity becomes easy enough for you.
All right.
So I will remove all of that and let's create a function.
So def how do we name our function.
Well we want to concatenate strings and actually uppercase strings.
So concatenate concatenate uppercase strings and I open the parentheses.
You can see this name starts to be a bit long but it's still not that long okay.
So as best practice is better to have short names.
But even more important than that, it's better to have names that are meaningful.
Okay.
So here it's pretty explicit.
So in the parentheses I'm going to add parameters.
How many strings do I have.
Well here I'm going to use two strings.
I'm just going to name them str underscore a and str underscore b.
Okay.
Since we are only going to use that inside this function okay.
And this is a local variable I can just use this name.
It's not going to be a problem.
So I close the parentheses I put a colon I go back to a new line with an indentation of four spaces
here.
And then let's do result.
What will be the result.
So we want to do str a plus str b.
This will concatenate the two strings.
But I also need to add a space in between okay.
So I'm going to add a space.
So we'll simply a quote like this with a space.
And then plus okay so I can do plus between two strings, but also between three strings.
I can add as many strings as I want.
So here I'm adding three strings.
This one that we get in a parameter, and then an empty character, and then the second string that
will concatenate the two strings with a space.
But we still need to put them uppercase.
So I will do the first.
So string a dot upper like this and open close parenthesis.
And the same thing for the strb upper.
This way we are going to first put the string a in uppercase, add a space and then the string B in
uppercase.
Let's save this file as.
So save or save as and let's name it activity one dot p y.
Okay.
So I'm going to follow the same template for all activities.
And then you can also download the code for each activity if you want to Click on okay.
So it is saved.
And then well if I run it the thing is you can see nothing happens.
Why?
Because we have defined a function but we don't use this function.
And actually we don't even use this function.
But we don't even return anything from the function.
So I can do return result.
Okay.
Because if I just create the function like this, what is it going to compute the concatenation and
put it inside the result variable.
But if we don't return it well we're going to lose this result.
But still it's not going to do anything because we don't call it.
So I'm going to go back to a new line.
And you can see it's important to go back to a new line with zero indentation here.
If I do this we are still in the function okay.
So I go here and I will do print concatenate concatenate.
So here I'm going to use also the autocompletion I'm going to use Ctrl space and then tab or enter.
So concatenate uppercase string.
I'm going to say the first string is hello.
Like this.
And then a comma and then world.
And then I close the parentheses and I need to close the parenthesis twice okay.
One for this function and also one for the print function.
Let's let's run it.
And you can see we have the correct result.
Hello world with a space and all uppercase.
Now let's say for example if you have only one parameter.
So let's say you don't give the correct amount of parameters.
So here you give two few parameters.
Let's see what happens.
You have an error of course that says missing one required argument okay.
So you need to provide exactly the same amount of parameters that you have in the function.
So if you have two here it's going to be two here.
If you have three you need to provide three Etc..
And look, what we can also do is because this is going to return a string, we need to pass a string
as a parameter.
So I can also call concatenate uppercase string here.
So let's do concatenate.
I'm going to use Ctrl and space again.
And let's put world like that okay.
And close the parenthesis.
So basically what we do is we first concatenate some strings and actually not just world but hello and
world.
We need to pass two parameters.
So we are going to call that first it's going to give us Hello world all uppercase.
And then we're going to use the result as an input parameter for this function.
So the same function again with hello.
And then the result of that.
And finally we print the whole thing okay.
You can see you can really go far when combining functions.
And make sure you can see that you close three parentheses okay.
Let's see what happens.
And now we have hello, Hello world because this one is going to give us Hello world.
And then we add another hello.
So hello, hello world.
And just to finish here with optimization.
Well again you can see we create a variable.
We just return this variable.
And this what anyway is created inside this function.
We are not going to use it outside because it's only available in this scope.
So if you just create a variable that you return immediately after that, you probably don't need the
variable anyway.
So instead of doing this, I'm just going to return the result and of course remove that line.
So now we return directly the result.
It's going to give us the same thing.
Great.
And that's the end of this first activity.
So if it was too hard once again come back to the previous lessons.
Try to do the activity again today, maybe another day okay.
Give it some time, some practice.
And at some point you will see you will manage to do it without any effort.