← Back to course
Python 11-12 / Week 04 / Mission Quest
6/6
Week 04 Β· Objects Working Together

Mission Quest

Mission Quest: Two notes, one box
// Names, references and objects that hold objects
⏱ about 30 min

Saturday: Mission Quest: Two Notes, One Box

Comet arrives with a shoebox and a pad of sticky notes. "I want to see aliasing with my own eyes," she says.

She sticks a note that says spots on the box, then a second note that says route on the same box.

Wren drops a pebble in the box. "What do you notice?" he asks. "Look inside through spots, then through route. Same pebble?"

Nova hovers above the box. "How can I help?" she asks. "Try a second box too. Then ask which notes change together."

Comet hands you the pad of notes. "Lead programmer, run this one with your family."

β—‡ TWO NOTES, ONE BOX
You need two small boxes or cups, sticky notes or paper labels, and a few small tokens like buttons or paper clips.
Write spots on a note and stick it on box A. Write route on another note and stick it on box A too. Two names, one box.
Your partner puts a token "through route" by dropping it into box A. Ask: how many tokens are "in spots" now? Check together.
Now make a copy: put box B next to it with the note copy_spots. Put the same number of tokens in box B.
Add a token to box B only. Ask: did spots change? Did copy_spots change? Swap roles and try a new move.
For a grown-up
This game acts out this week's idea. In Python, a name is like a note stuck on an object, not a box of its own.
Ask your learner to explain why the two notes on box A always agree, and why box B can be different.
There is nothing to type today. If your learner wants, they can rerun alias_sample.py from Monday and compare it with the boxes.
  1. Two notes on one box are like two names for one object: aliases.
  2. A second box with the same tokens is like a copy: equal values, separate object.
  3. In code, is asks "same box?" and == asks "same tokens?"
WEEK 4 CHECK
  • Read the question.
  • Tap your answer.
route = spots, then route.append("S05"). Does spots now hold S05?
Which call to Pip hands back a copy, so changing it cannot empty Pip?
Pip has a capacity of 3 and holds 3 samples. What does pip.pick_up(s) return?
StatementTrue or false?
A function can change an object passed to it.?
x == y being True means x is y must be True.?
A shallow copy is a new list of the same objects.?
WHY THIS EXERCISEis asks about identity and == about values, and a shallow copy shares the objects inside it.

Great work this week. Next week the test field becomes a grid that Pip can read.

← Friday