Scope

The questions below are due on Sunday July 14, 2024; 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.

Consider the below program, separated into pieces. Indicate the value of the prompted expressions. If evaluating the expression would cause an error, write error in the box. If an expression is a function, write function in the box. If an expression is a string, make sure to wrap it in quoatation marks.

An environment diagram may be particularly helpful here. Relevant readings include the custom function example from unit 4

three = "three"

def one():
    one = 1
    two = 2
    three = 3
    return 1

a = one()
print(three)

What's the value of a?

What's the value of three that will be printed in the last line?

def two():
    return 2

one = two
two = one
b = one()
c = two

What's the value of b?

What's the value of c?

Next Exercise: First Class Functions

Back to exercises