Exercise

The keyword nonlocal and nested functions

Let's once again work further on your mastery of scope! In this exercise, you will use the keyword nonlocal within a nested function to alter the value of a variable defined in the enclosing scope.

Instructions

100 XP
  • Assign to echo_word the string word, concatenated with itself.
  • Use the keyword nonlocal to alter the value of echo_word in the enclosing scope.
  • Alter echo_word to echo_word concatenated with '!!!'.
  • Call the function echo_shout(), passing it a single argument 'hello'.