For a teacher with a class? The classroom edition has the full plan, slides and standards.

Homeschooling PDF

Family edition

Pseudocode Tracer: Assignment Is a Copy

Ages 14-18 · about 45 minutes, in one sitting

Your teen opens a free tracer that runs the pseudocode used on the AP Computer Science Principles exam and predicts, line by line, what each variable will hold. The tracer stops before each key line, checks the prediction, and shows what really happened. The big idea is the exam's first rule: the arrow copies a value, it does not link two names.

What you need

Before you start: try it once yourself

Step through the starter, the swap and one exam question yourself once before you start, about ten minutes.

  1. Open the lesson. Go to mytekdev.com/try/pseudocode?lesson=assignment-is-a-copy&ref=fam-pseudo-1. The starter program is on the left, with a ? in front of lines 3, 5 and 8.
  2. Step and predict. Press Step until it stops at line 3 and asks Line 3 is next. What will score be after it runs? Type 10 and press Check: Not yet. It was 15. Step on to line 5 and answer 10: Right.
  3. Finish the run. Keep stepping (line 8 asks about lives: 4). The program displays 15, 10 and 4.
  4. Swap. Choose Example, Swapping two values, and step through. The first try displays 8 8, the second 8 3. Open the Trace table tab to see a row for each change.
  5. Exam question. Choose Example, Order of operations. Open Teach, then Exam question, and pick a choice. The right one is 18 28 3 2.5.
The Pseudocode Tracer with the starter program. Line 2, best ← score, is highlighted, the Variables panel shows score 10 and best 10 marked CHANGED, and a box asks: Line 3 is next. What will score be after it runs? with an answer field and a Check button.

The tracer stops before a ? line and checks the prediction.

The Exam question panel for the Order of operations example: What does this program display? with choice A, 18 28 3 2.5, and choice B, 28 28 3 2.5, and a box for a choice of your own.

Exam question: each wrong choice is what a real mistake displays.

Everything runs in the browser. Choosing a new Example replaces the program; opening the lesson link in a new tab brings the starter back.

The ideas, in plain words

Every program on the AP CSP exam is written in the exam reference sheet's notation, in text and in blocks, and Big Idea 3, Algorithms and Programming, is 30 to 35 percent of the multiple-choice section. Topic 3.1 asks learners to determine the value of a variable as a result of an assignment (AAP-1.B). The CED spells the rule out: the arrow "evaluates expression and then assigns a copy of the result to the variable", and the value stored "will be the most recent value assigned" (AAP-1.B.2 and AAP-1.B.3).

The common mistake is to read b ← a as "b is a", a link that keeps them equal. It is an action that happens once: work out the right side, copy the result into the left side, move on. That is why a swap needs a third variable. Without one, the first assignment destroys the value the second one needs.

Topic 3.3 adds expressions (AAP-2.C). Multiplication, division and MOD happen before addition and subtraction. a MOD b is the remainder, defined on the sheet for a 0 or more and b more than 0. Division with / gives the ordinary result, so 17 / 5 is 3.4. Anyone who knows Java or older Python may expect 3. The tracer follows the sheet, and its Outside the sheet page lists every choice it makes where the sheet says nothing.

Your child might askA good answer
Isn't b ← a the same as b = a in math?No. In math, = says two things are always equal. The arrow is an action: copy once, now.
Why does Not yet show me the answer?So the trace can keep going. Write the right value in the table and look for the reason before the next ? line.
Does the exam use = or ←?The arrow, for assignment. The exam uses = to compare two values, as in IF(a = b).
What is 7 MOD 7?0: 7 divides evenly, so there is no remainder.

Do it together

  1. Before opening anything, write a ← 1, b ← a, a ← 2, DISPLAY(b) on paper. Ask your teen whether it shows 1 or 2, and why.

    You'll know it worked when: Either answer is fine for now. The rest of the hour settles it.

  2. Open mytekdev.com/try/pseudocode?lesson=assignment-is-a-copy&ref=fam-pseudo-1. A short guide runs along the bottom; follow it together. Press Step to run one line at a time and watch the Variables panel on the right.

    If you get stuck: A line with a ? in front of it stops before it runs and asks a question. Type the answer and press Check.

  3. At line 3 the tracer asks what score will be. At line 5 it asks what DISPLAY(best) will show. Your teen answers each before checking.

    You'll know it worked when: score becomes 15. DISPLAY(best) shows 10: best got a copy of the old score, so changing score later did not change it. That is also why the paper example shows 1.

  4. Choose Example, then Swapping two values. Before stepping, your teen predicts what the first try, lines 1 to 6, displays. Then step through.

    You'll know it worked when: The first try shows 8 and 8, because the 3 was replaced before it was copied. The second, with temp, shows 8 and 3.

  5. Open the Trace table tab and copy it onto paper, one row for each change.

    If you get stuck: Each row is one moment. A blank cell means that variable did not change at that moment.

  6. Choose Example, then Order of operations. Open Teach, then Exam question, and pick an answer before stepping.

    You'll know it worked when: The right answer is 18 28 3 2.5: multiplication happens before addition, MOD gives the remainder, and / is ordinary division.

  7. Finish with one question: after b ← a, why does changing a later leave b alone?

    You'll know it worked when: Your teen explains that the arrow stored a copy of the value at that moment, and the two variables are separate.

Talk about it

Ask these while you work together. A child who has understood the lesson can answer them without help:

The second one is the real test. A child who can point at the line where the 3 disappeared understands assignment as an action, not a link.

For younger and older kids

Younger: For ages 12 and 13, do the warm-up and the swap together, and skip MOD.

Older: For older teens heading for the exam, try Example, Copying a list, and explain why the reference sheet copies a whole list too, unlike Python.

Keep going

Bring it into other subjects

For your records

Ready to copy into an hour log, a portfolio or a transcript.

LessonPseudocode Tracer: Assignment Is a Copy
SubjectsComputer science
Time45 minutes
What we didTraced AP Computer Science Principles exam pseudocode line by line in a step-by-step tracer: predicted each variable's value before checking, filled a trace table, explained why assignment copies a value, traced a swap with a temporary variable, and answered exam-style questions on order of operations and MOD.
Skills practicedtracing variables and assignment; trace tables; order of operations and MOD; exam reference sheet notation

Pseudocode Tracer: Assignment Is a Copy

Activity sheet (optional)

Name: ______________________________ Date: ______________

Open the tracer: scan the QR code, or go to mytekdev.com/try/pseudocode?lesson=assignment-is-a-copy

Essential question: When the reference sheet's arrow runs, what exactly does the variable on its left hold afterward?

Warm-up: a ← 1, b ← a, a ← 2, DISPLAY(b). My vote: ____ because ______________________________

Trace table for Swapping two values (first try), one row for each change:

LinexyDisplayed
1
2
3
4
5
6

1. Which line destroyed the value 3 in the first swap? Explain.

2. In Order of operations, the choice 28 28 3 2.5 is wrong. What mistake gives that answer?

Quick check

Name: ______________________________

1. x ← 4, y ← x, x ← x + 3, y ← y * 2, DISPLAY(x), DISPLAY(y). What is displayed? (A) 7 8, (B) 14 14, (C) 7 14.

2. What does DISPLAY(17 MOD 5) display? (A) 3, (B) 3.4, (C) 2.

3. Explain why a swap of two variables needs a third variable.

Answers

Measured in the tracer: the starter displays 15, 10 and 4. Swapping two values displays 8 8 for the first try and 8 3 with temp. Order of operations displays 18 28 3 2.5, and the no-precedence reading gives 28 28 3 2.5. Every choice was worked out by running a program, the question as written and each wrong choice with its mistake built in: question 1's B is the program with y linked to x, and C is y taking x's newest value; question 2's A is MOD read as the quotient, and B is 17 / 5.

QuestionAnswerWhy
1Ay got a copy of 4, so x ← x + 3 changes only x. Then y doubles to 8.
2CMOD is the remainder: 17 = 3 × 5 + 2.
3Saving one value firstA good answer says: the first assignment replaces one value, so it must be copied into a third variable before it is lost.

If your state or umbrella school asks, this lesson covers AP CSP CED 2023 AAP-1.B, AP CSP CED 2023 AAP-2.C, CSTA 2017 2-AP-11.

The Pseudocode Tracer runs the notation of the AP Computer Science Principles Exam Reference Sheet. AP is a trademark registered by College Board, which is not affiliated with, and does not endorse, this site or these lessons.