Classes: Environment Diagrams
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.
Problem 1 - Diagramming Interface
In order to practice drawing environment diagrams, this question tasks you with using a drag-and-drop interface to construct a diagram.
The later questions on this page will ask you to develop diagrams on your own, but this question is designed to help you familiarize yourself with the interface itself.
Please use the interface below to re-create the following diagram, representing
the state of the program below just before the call to Foo.__init__ returned.
class Foo():
def __init__(self, x):
self.bar = x
y = Foo(2)
Note that the global frame has been provided for you.
For instructions on how to use the interface, please click on the ℹ️ icon.
Problem 2 - Class Definition
Create a diagram representing the result of executing the following code, consisting of a single class definition. Remember that a class object must contain its attributes: the variables and methods defined within the class.
class Foo():
w = 8
def __init__(self, name):
self.name = name
Show/Hide Hints
- There should be the global frame and three other objects: a class with 2 attributes, an int, and a function.
- Remember to mark the enclosing frame of the function object.
Problem 3 - Code to Diagram 1
Consider the following diagram:
In the box below, enter any valid Python program that, when executed, would lead to the diagram above.
Problem 4 - Code to Diagram 2
Consider the following diagram:
In the box below, enter any valid Python program that, when executed, would lead to the diagram above.
Next Exercise: Classes: Account
6.s090

