Functions and Scope

The questions below are due on Sunday July 06, 2025; 10:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

For each of the following programs, enter the result of the print statement after executing the program.

If evaluating the print statement in question would cause an error, write error in the box.

x = 4

def fun(x):
    x = 1
    return x

y = 5
z = fun(y)

print([x, y, z])

def fun(x):
    x[0] = x[0] + 1
    return x

x = [0]
y = [1, 2, 3]
z = fun(y)

print([x, y, z])

x = 5.5
y = 2

def fun(y):
    y += 2
    return bar(y)

def bar(x):
    x = x * y
    return x

z = fun(10)

print([x, y, z])

x = 5.5
y = 2

def bar(x):
    z = x
    return z

fun(10)

print([x, y, z])

Next Exercise: Environment Diagrams

Back to exercises