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!
Latihan ini adalah bagian dari kursus
Introduction to Functions in Python
Petunjuk latihan
- Complete the function header by adding the parameter name,
word. - Assign the result of concatenating
wordwith'!!!'toshout_word. - Print the value of
shout_word. - Call the
shout()function, passing to it the string,'congratulations'.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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'