Single-parameter functions
Congratulations! You have successfully defined and called your own function! That's pretty cool.
In the previous exercise, you defined and called the function shout()
, which printed out a string concatenated with '!!!'
.
You will now update shout()
by adding a parameter so that it can accept and process any string argument passed to it. Also note that shout(word)
, the part of the header that specifies the function name and parameter(s), is known as the signature of the function. You may encounter this term in the wild!
This exercise is part of the course
Introduction to Functions in Python
Exercise instructions
- Complete the function header by adding the parameter name,
word
. - Assign the result of concatenating
word
with'!!!'
toshout_word
. - Print the value of
shout_word
. - Call the
shout()
function, passing to it the string,'congratulations'
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define shout with the parameter, word
def shout(____):
"""Print a string with three exclamation marks"""
# Concatenate the strings: shout_word
____ = ____ + '!!!'
# Print shout_word
print(____)
# Call shout with the string 'congratulations'