Get startedGet started for free

Functions with multiple default arguments

You've now defined a function that uses a default argument - don't stop there just yet! You will now try your hand at defining a function with more than one default argument and then calling this function in various ways.

After defining the function, you will call it by supplying values to all the default arguments of the function. Additionally, you will call the function by not passing a value to one of the default arguments - see how that changes the output of your function!

This exercise is part of the course

Introduction to Functions in Python

View Course

Exercise instructions

  • Complete the function header with the function name shout_echo. It accepts an argument word1, a default argument echo with default value 1 and a default argument intense with default value False, in that order.
  • In the body of the if statement, make the string object echo_word upper case by applying the method .upper() on it.
  • Call shout_echo() with the string, "Hey", the value 5 for echo and the value True for intense. Assign the result to with_big_echo.
  • Call shout_echo() with the string "Hey" and the value True for intense. Assign the result to big_no_echo.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Define shout_echo
def ____(____, ____, ____):
    """Concatenate echo copies of word1 and three
    exclamation marks at the end of the string."""

    # Concatenate echo copies of word1 using *: echo_word
    echo_word = word1 * echo

    # Make echo_word uppercase if intense is True
    if intense is True:
        # Make uppercase and concatenate '!!!': echo_word_new
        echo_word_new = ____ + '!!!'
    else:
        # Concatenate '!!!' to echo_word: echo_word_new
        echo_word_new = echo_word + '!!!'

    # Return echo_word_new
    return echo_word_new

# Call shout_echo() with "Hey", echo=5 and intense=True: with_big_echo
with_big_echo = ____

# Call shout_echo() with "Hey" and intense=True: big_no_echo
big_no_echo = ____

# Print values
print(with_big_echo)
print(big_no_echo)
Edit and Run Code