AP CSP Day 23: Agile Methods

Big Idea 3: Algorithms & Programming
Cycle 1 • Day 23 Practice • Medium Difficulty
Focus: Variables & Assignment

Practice Question

What is displayed after the following code runs?

a ← 3
b ← 7
a ← a + b
b ← a - b
DISPLAY(a)
DISPLAY(b)
Why This Answer?

Starting: a=3, b=7. After a ← a + b: a = 3+7 = 10. After b ← a - b: b = 10-7 = 3 (using the current value of a, which is now 10). Display shows 10 then 3.

Why Not the Others?

A) Students who pick this use the current a (10) correctly for the first display but forget to update b. B is correct because b changes too. C) Both variables are modified by the code. B) This reverses the displayed order or uses wrong intermediate values.

Common Mistake
Watch Out!

Students use the original value of a (3) instead of the updated value (10) when computing b ← a - b. Always use the most recent value of a variable.

AP Exam Tip

When a variable appears on both sides of an assignment, the right side is evaluated first using current values, then the result is stored on the left. Update your trace immediately.

Keep Practicing!

Consistent daily practice is the key to AP CSP success.

AP CSP Resources Get 1-on-1 Help
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.