AP CSP Topic 3.1 Guided Notes - Variables and Assignments

Big Idea 3: Algorithms and Programming · Topic 3.1 · Guided Notes (Student)

Variables and Assignments — Guided Notes

Fill these in during class or catch up here if you were absent. Print this page or work on paper — then check yourself with the CFUs on the Topic 3.1 page.

Print these notesAll CSP topics

Day 1: Giving Data a Name

Today’s objectives

  • Explain that a variable is an abstraction that holds one value at a time, and why a meaningful name makes a program readable (LO AAP-1.A)
  • Name the four data types the CED lists — numbers, Booleans, lists, and strings — and choose the type best suited to a given value (LO AAP-1.A)

Bell ringer

Follow this recipe EXACTLY as written, out loud, with a partner: 'Take the number. Add the number to itself. To that result, add the number again. Now double the whole thing. Report the answer.' Use the number 7.

Write 2–4 sentences: Where did you lose track of which 'the number' meant what? Rewrite the recipe so a stranger could follow it with zero confusion. What did you have to add to make it clear?

01. What a Variable Is

Key Vocabulary (LO AAP-1.A)

Term Definition (write it)
Variable
Value
Data type
Boolean
Meaningful name

A Named Box That Holds One Value

  • A variable is an abstraction because you use its name and .
  • At any moment a variable's storage represents .
  • That one value is allowed to be .

Store a Value, Then Use It

The name 'score' holds the value 5; DISPLAY then shows what's inside.

AP Pseudocode (what the exam tests)

score ← 5
DISPLAY(score)

Python (the runnable version)

score = 5
print(score)

Output

5

Run and edit this yourself in the coding exercises for this topic.

Names Are for Humans

Vague names

Meaningful names

  • A meaningful variable name improves .
  • Meaningful vs vague names run identically, so good names exist to help .

AP TIP: The machine does not care about names — readability is entirely for the humans who read, test, and fix the code.

Stop and think

  1. In two sentences, explain what it means to say a variable is an 'abstraction that holds one value at a time.' Use the labeled-box idea.
  2. A program uses a variable named d for a person's date of birth. Rename it to something meaningful and explain, using the word readability, why your name is better.
  3. A classmate says 'a variable can hold lots of values at once, like all the quiz scores.' Correct the wording precisely — what one thing does the variable actually hold?

Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.1 page.

02. Types and Choosing a Type

Four Types the CED Names

  • Some values fit one type better than another, so the programmer .
  • A Boolean is best suited to a value that is .
  • 's key idea is that .

One Variable Per Type

A number, a string, a Boolean, and a list — each variable holds one value of its kind.

AP Pseudocode (what the exam tests)

age ← 15
name ← "Ada"
ready ← true
scores ← [88, 92]
DISPLAY(name)

Python (the runnable version)

age = 15
name = "Ada"
ready = True
scores = [88, 92]
print(name)

Output

Ada

Run and edit this yourself in the coding exercises for this topic.

Match the Value to the Type

For each value, pick the type that fits best. The tricky ones are values that LOOK like numbers but should not be.

Complete the empty cells.

Value to store Best type Why this type
A final exam score, like 88 Number Scores get averaged and compared, so arithmetic must work on them
Whether a user is logged in There are only two states — true or false
A person's full name A name is ordered text, not a quantity you calculate with
Everyone's quiz grades together List Many values must be held in order under one variable name
A phone number like 5551234567 It is never added or averaged, and leading digits and format must be preserved

Watch out — “If It's All Digits, It's a Number”

Myth: Any value made of digits — a phone number, a ZIP code, a student ID — should be stored as a number type.

Explain why this is wrong:

Stop and think

  1. For each value, name the best type and one sentence of justification: (a) a thermostat's current temperature, (b) whether it is raining, (c) a shopping list of item names.
  2. A programmer stores a student ID '00847' as a number and later it prints as 847. Explain the bug and the type that fixes it.
  3. In one sentence, state the test you use to decide whether a digit-filled value should be a number or a string.

Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.1 page.

Today in one box

  • A variable is an abstraction that holds exactly one value at a time — the value may itself be a list
  • Meaningful names improve readability and show what a value represents; the machine does not care
  • The four types the CED names: numbers, Booleans, lists, and strings
  • Some values fit one type better than another — digit labels like ZIP codes belong in strings

Before next class: Before tomorrow, predict it: a ← 1, then b ← a, then a ← 2. Now DISPLAY(b). Write down your answer and, more importantly, your reasoning.

Day 2: Making the Value Move

Today’s objectives

  • Use the assignment operator ← to change the value a variable holds, knowing it evaluates the right side first, then stores a copy of the result (LO AAP-1.B)
  • Determine a variable's value after a sequence of assignments, applying the most-recent-value rule to trace and swap puzzles (LO AAP-1.B)

Bell ringer

Yesterday's teaser, now decide it. The program runs: a ← 1, then b ← a, then a ← 2, then DISPLAY(b). Three classmates predict b will show 2, 1, and 0.

Who is right, and exactly why? Write down what b holds after EACH line, and name the mistake the two wrong classmates made.

01. The Assignment Operator

Assignment: Evaluate, Then Store a Copy

  • The assignment operator's job is to .
  • The statement a ← expression works by .
  • Storing a copy (not a link) means the variable afterward is .

The Right Side Runs First

count ← count + 3 evaluates 5 + 3, then stores the copy 8 back into count.

AP Pseudocode (what the exam tests)

count ← 5
count ← count + 3
DISPLAY(count)

Python (the runnable version)

count = 5
count = count + 3
print(count)

Output

8

Run and edit this yourself in the coding exercises for this topic.

← Is Not the = From Math Class

Math =

Assignment ←

  • The assignment arrow should be read as , never as 'equals.'
  • count ← count + 3 is sensible in code but x = x + 3 is impossible in math because .

AP TIP: Read ← as 'becomes' or 'gets,' never as 'equals.' 'count becomes count + 3' is instantly sensible.

Stop and think

  1. Translate a ← b + 2 into a plain-English command using the word 'becomes,' and describe the two steps the computer performs in order.
  2. A classmate says 'total ← total * 2 can't be right — total can't equal itself doubled.' Explain why the statement is perfectly valid in code.
  3. After price ← 10 and price ← price - 4, what does price hold? Show the right-side evaluation that produces it.

Answer in complete sentences. Then check yourself with the matching CFUs on the Topic 3.1 page.

02. Most Recent Value & Copies

A Variable Keeps Its Most Recent Value

  • The value stored in a variable is always .
  • In a ← 1; b ← a; a ← 2, DISPLAY(b) shows 1 because .
  • b ← a does NOT create .

The Classic Puzzle

b keeps the copy it received; changing a afterward does nothing to b.

AP Pseudocode (what the exam tests)

a ← 1
b ← a
a ← 2
DISPLAY(b)

Python (the runnable version)

a = 1
b = a
a = 2
print(b)

Output

1

Run and edit this yourself in the coding exercises for this topic.

Trace a Swap, Line by Line

Swapping two variables needs a temporary holder. Fill in each variable's value AFTER the line runs — a dash means 'no value yet.'

Complete the empty cells.

After line Statement x y temp
1 x ← 4 4
2 y ← 9 4 9
3 temp ← x 4 9
4 x ← y 9 4
5 y ← temp 9 4

Watch out — “b ← a Links b to a”

Myth: After b ← a, the variables b and a are tied together, so a later change to a also changes b.

Explain why this is wrong:

Stop and think

  1. Trace: p ← 5, q ← p, p ← p + 4, DISPLAY(q). What does q show? Write q's value after each line.
  2. Trace the swap: m ← 7, n ← 2, temp ← m, m ← n, n ← temp. Give the final values of m and n, and explain what temp saved.
  3. A programmer tries to swap with only m ← n, n ← m (no temp). Predict the result for m ← 7, n ← 2 and explain what went wrong.
  4. In one sentence, state the rule that determines the value a variable holds after any sequence of assignments.

Show every step. Then check yourself with the matching CFUs on the Topic 3.1 page.

Common AP Traps

Three ways Topic 3.1 loses points on the exam — one minute now, real points in May.

Assignment is not equality — in your own words:

b ← a copies the VALUE, not a link — in your own words:

Only the most recent value — in your own words:

Variables and Assignments, in One Slide

  • A variable is an abstraction that holds exactly one value at a time; meaningful names make code readable.
  • The CED names four types — numbers, Booleans, lists, strings — and some values fit one type better than another.
  • The assignment operator ← changes a variable's value: evaluate the right side, then store a COPY on the left.
  • A variable keeps its MOST RECENT value; b ← a copies a value, it does not link — so a ← 1; b ← a; a ← 2; DISPLAY(b) shows 1.

Exit check — I can…

  • ☐  explain that a variable is an abstraction holding one value at a time, and choose a meaningful name (LO AAP-1.A)
  • ☐  name the four types and pick the type best suited to a given value (LO AAP-1.A)
  • ☐  use the assignment operator ←, evaluating the right side before storing a copy (LO AAP-1.B)
  • ☐  trace a sequence of assignments and give a variable's most recent value, including swaps (LO AAP-1.B)

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]