Variable Memory Model¶
Run the Variable Memory Model MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim¶
score = 10 is invisible magic until you can see the box. This MicroSim makes
the sticky-note metaphor operational: each assignment creates or updates a
labeled memory box, each read outlines the box being looked at in blue, and
each reassignment shows the old value being replaced (with a small "was 10"
note so students see that the old value is gone).
Learning objective: The student will be able to explain what happens in memory when a variable is created, read, and reassigned.
- Bloom's Taxonomy (2001): Understand — explain, interpret, predict
- Interaction pattern: step-through worked example with labeled memory boxes (no animation)
How to Use¶
- Read the script on the left and predict how many boxes will exist when it finishes, and what each will hold.
- Click Next Step to run one line. Orange means a box is being written; blue means a box is being read.
- Watch
score = score + 5carefully: Python reads the old value first, then replaces it. - Try all three programs. Copy Surprise answers a classic question:
after
b = a, does changingaalso changeb?
Iframe Embed Code¶
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan¶
Grade Level¶
Upper elementary and middle school (ages 10-14), Chapter 3 (Variables and Numbers)
Duration¶
10 minutes
Prerequisites¶
- print() and the idea that programs run top to bottom (Chapters 1-2)
Activities¶
- Predict (3 min): For the "Game Score" script, students write down the final value of every variable before stepping.
- Step and check (4 min): Step through and compare. Pause on
score = score + 5and ask: "Which happens first — the read or the write?" - Copy Surprise (3 min): Students predict what
print(b)shows aftera = 7. Most expect 7; the sim shows why it is 5.
Assessment¶
- Student can state that assignment stores a value and reassignment replaces it
- Student correctly predicts the output of a 4-line script using reassignment
- Student can explain why changing
aafterb = adoes not changeb
References¶
- Python Tutorial — Numbers and Variables — official introduction to assignment
- p5.js — the JavaScript library used to build this MicroSim