Function Call Flow¶
Run the Function Call Flow MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim¶
"Why doesn't def run my code?" and "where does the argument go?" are the two
most common questions in the functions chapter. This MicroSim answers both
visually. The def step stores the function as a green "machine" without
running it. Each call step shows the argument flying into the parameter slot,
the body computing, and the return value flying back to replace the call
site. The same function runs twice with different arguments, so students see
why functions are reusable.
Learning objective: The student will be able to trace a function call, explaining how the argument value binds to the parameter and how the return value replaces the call site.
- Bloom's Taxonomy (2001): Understand — explain, trace, infer
- Interaction pattern: step-through with data-flow arrows and concrete values visible at every step (no animation)
How to Use¶
- Read the program and predict the two numbers it will print.
- Click Next Step. The first step is
def— notice that nothing runs; Python only stores the recipe. - Watch the blue arrow carry the argument
5into the parameter slotn, and the orange arrow carry the returned10back out. - Keep stepping to see the same machine run again with
7.
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 4 (Functions and Objects)
Duration¶
10 minutes
Prerequisites¶
- Variables and assignment (Chapter 3)
- The idea that programs run top to bottom (Chapters 1-2)
Activities¶
- Predict (3 min): Students write down the two numbers the program will print, before touching the sim.
- Trace (5 min): Step through all 9 steps. Pause at step 1 and ask: "Why is the output still empty after Python read the def block?"
- Reuse (2 min): Ask students what would print if a third line called
double(100)— they should be able to trace it mentally now.
Assessment¶
- Student can explain why the function body does not run at the
defline - Student can state where the argument value goes and where the return value ends up
- Student correctly traces a new call like
double(12)without the sim
References¶
- Python Tutorial — Defining Functions — official documentation
- p5.js — the JavaScript library used to build this MicroSim