Add the Shout Function
00:00
Next, hop over to the string.py
file, and I’ll add the request for the exercise in here
00:10 and format the comment a little bit so you can read everything on the screen.
00:17
So the request for the string.py
module was to add a function called shout()
that takes a single string parameter and returns a new string with all of the letters in uppercase.
00:30
So maybe let’s order this a little bit so that we have basically a small little task list where we already have solved the first part because we are in the string
module, so we can already delete the first line of the comment and tackle the next one: add a function called shout()
.
00:50
Let’s do this. def shout():
and on the next line, indented, let’s add a pass
for now and look at the next to-do: the function should take a single string parameter.
01:09 That means you need to add something in the parentheses. Now, when you define a function and you have to define a parameter, you should be thoughtful of how to name this parameter because you will use it in the function, and it should be descriptive.
01:23
Maybe in this case, you could just stick with calling this string string
because that’s what it is. Or you could be even more verbose and say string_to_shout
.
01:37
But since the function is already named shout()
, it’s kind of clear that you shout the string. So let’s stick with string
in this case.
01:47
So we have a function called shout()
that takes a single string parameter. So we have solved this part. And then the next part is that this function should return a new string,
02:02 but at the moment, it’s the same string.
02:05
So the last part of this task is to return the string with all letters in uppercase, and in Python, you can do this with the .upper()
method. When you save it, you can try this function out by running the module and then calling shout()
.
02:27
We add in a string. Let’s make "hello"
in lowercase. And when you run it, it says HELLO
in uppercase.
02:35 That means this task is done. You can remove all the comments and move on to the next task of the challenge.
Become a Member to join the conversation.