Aan de slagGa gratis aan de slag

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!

Deze oefening maakt deel uit van de cursus

Introduction to Functions in Python

Cursus bekijken

Oefeninstructies

  • Complete the function header by adding the parameter name, word.
  • Assign the result of concatenating word with '!!!' to shout_word.
  • Print the value of shout_word.
  • Call the shout() function, passing to it the string, 'congratulations'.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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'
Code bewerken en uitvoeren