AP CSP Unit 4: Variables, Expressions, and Lists

34 multiple-choice questions on AP Computer Science Principles Unit 4, Variables, Expressions, and Lists, organized by topic. They are not tied to any one class or teacher: they follow the College Board course framework. Learn the 7 key terms with the flashcards first, then test yourself. Every answer comes with a short explanation.

Take the practice test · Flashcards · All study tools

What it covers

  1. 4.1 Variables and assignment
  2. 4.2 Expressions, strings, and operators
  3. 4.3 Boolean expressions and conditionals
  4. 4.4 Lists

Key terms

4.4 Lists

Assignment operator (←)
Stores the value of an expression in a variable
MOD
Returns the remainder of a division
Boolean expression
An expression that evaluates to true or false
String concatenation
Joining strings end to end
List
An ordered sequence of elements
APPEND / INSERT / REMOVE
List operations that add to the end, insert at an index, or delete at an index
Data abstraction
Managing complexity by naming a collection of data without referring to its details

Sample practice questions

  1. In AP pseudocode, what does the statement a ← 7 do?

    1. It assigns the value 7 to the variable a
    2. It checks whether the variable a equals 7
    3. It displays the value 7 next to the name a
    4. It adds 7 to the current value stored in a

    Answer: A. It assigns the value 7 to the variable a The arrow is the assignment operator.

  2. What is the value of 17 MOD 5 in AP pseudocode?

    1. 3
    2. 3.4
    3. 2
    4. 5

    Answer: C. 2 MOD gives the remainder after division.

  3. What is the value of (5 > 3) AND (2 > 4)?

    1. true
    2. false
    3. 5
    4. 2

    Answer: B. false AND requires both conditions to be true.

  4. In AP pseudocode, list indices start at

    1. 0
    2. 1
    3. −1
    4. any number the programmer chooses

    Answer: B. 1 The AP CSP reference sheet uses index 1 for the first element.

  5. What is displayed? a ← 3; b ← a; a ← 5; DISPLAY(b)

    1. 5
    2. 3
    3. 8
    4. a

    Answer: B. 3 b received a copy of a's value (3) before a changed.

  6. What is the value of 10 MOD 2?

    1. 5
    2. 0
    3. 2
    4. 1

    Answer: B. 0 10 divides evenly by 2.

  7. What is the value of NOT (3 = 3) OR (4 < 5)?

    1. false
    2. 3
    3. 4
    4. true

    Answer: D. true NOT (3 = 3) is false, but 4 < 5 is true, so OR gives true.

  8. Given myList ← [10, 20, 30, 40], what is myList[2]?

    1. 30
    2. 10
    3. An error
    4. 20

    Answer: D. 20 Index 1 is 10 and index 2 is 20.

  9. What is displayed? x ← 4; x ← x + 2; x ← x * 3; DISPLAY(x)

    1. 10
    2. 14
    3. 12
    4. 18

    Answer: D. 18 x becomes 6, then 18.

  10. Which expression evaluates to true if the number n is odd?

    1. n MOD 2 = 0
    2. n / 2 = 1
    3. n MOD 2 = 1
    4. n MOD 1 = 2

    Answer: C. n MOD 2 = 1 Odd positive numbers leave remainder 1 when divided by 2.

Practice all 34 questions

More AP Computer Science Principles

Studying for a test in your own class? Make a practice test from your class notes.