human
I am working on the file "Python Quick Reference/Functions.ipynb".
The first task is:
10. Nonlocal and global
 nonlocal allows you to modify a variable outside your scope (but not global scope)
Can you write Python code for it?
 Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

def outside():
    msg = "Outside!"
    def inside():
        msg = "Inside!"
        print(msg)
    inside()
    print(msg) # this prints 'Outside!' even though Inside() mosifies a variable called msg (its a local copy)

outside()

# to have a variable refer to something outside local scope use nonlocal
def outside():
    msg = "Outside!"
    def inside():
        nonlocal msg
        msg = "Inside!"
        print(msg)
    inside()
    print(msg) 

outside()

# the global keyword makes a variable reference a global variable rather then a copy
msg = 'Global!!'

def outside():
    msg = "Outside!"
    def inside():
        global msg
        msg = "Inside!"
        print(msg)
    inside()
    print(msg) # this prints 'Outside!' because the copy in Inside() references the global variable

outside()
msg