AP Computer Science Principles Practice Quiz: Variables and Assignments
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 16 questions to check your progress.
Question 1 of 16
All Questions (16)
A) To perform calculations
B) To hold a value
C) To define a data type
D) To execute a command
Correct Answer: B
The text states that 'A variable is an abstraction inside a program that can hold a value.' Its main purpose is to represent and store a value.
A) 95
B) score
C) The value is unknown.
D) ← 95
Correct Answer: A
The assignment operator '←' assigns the value on the right (95) to the variable on the left (`score`). The text explains this process helps 'determine the value of a variable as a result of an assignment.'
A) It makes the program run faster.
B) It reduces the amount of memory the program uses.
C) It helps with the readability and understanding of the code.
D) It is required by the assignment operator.
Correct Answer: C
The provided content explicitly states, 'Using meaningful variable names helps with the readability of program code and understanding of what values are represented by the variables.'
A) 10
B) 15
C) 25
D) An error occurs.
Correct Answer: B
The text states, 'The value stored in a variable will be the most recent value assigned.' The variable `count` is first assigned 10, but then it is reassigned the value 15. Therefore, 15 is the final value.
A) It compares two values for equality.
B) It evaluates an expression and assigns a copy of the result to a variable.
C) It declares a new variable without assigning a value.
D) It links two variables so they always have the same value.
Correct Answer: B
The content states, 'The assignment operator evaluates an expression and then assigns a copy of the result to the variable.' This is its core function.
A) Number
B) Boolean
C) List
D) String
Correct Answer: D
The text mentions that programming languages provide types like numbers, Booleans, lists, and strings. A name is a sequence of characters, which is best represented by the String data type.
A) `valA` is 100, `valB` is 100
B) `valA` is 100, `valB` is 50
C) `valA` is 50, `valB` is 100
D) `valA` is 50, `valB` is 50
Correct Answer: A
First, `valA` is 50 and `valB` is 100. The third line, `valA ← valB`, evaluates the expression on the right (`valB`, which is 100) and assigns that value to `valA`. The value of `valB` does not change. Therefore, `valA` becomes 100 and `valB` remains 100.
A) A variable `age` holding the number 25.
B) A variable `isStudent` holding the Boolean value `true`.
C) A variable `shoppingCart` holding the items ['milk', 'bread', 'eggs'].
D) A variable `finalScore` that is assigned the result of `10 + 20`.
Correct Answer: C
This option shows a single variable, `shoppingCart`, holding a list, which is a collection that contains multiple values ('milk', 'bread', 'eggs'). This directly aligns with the description in the provided content.
A) 10
B) 20
C) 30
D) The value is undefined.
Correct Answer: A
The assignment `y ← x` assigns a *copy* of the current value of `x` (which is 10) to `y`. When `x` is later changed to 20, it does not affect the copy of the value that was already assigned to `y`. Therefore, `y` remains 10.
A) Numbers
B) Booleans
C) Characters
D) Strings
Correct Answer: C
The text explicitly mentions that 'These types include numbers, Booleans, lists, and strings.' It does not mention 'Characters' as a distinct type.
A) `x ← 1`
B) `terms ← 'yes'`
C) `hasAcceptedTerms ← true`
D) `data ← [true]`
Correct Answer: C
This choice uses a meaningful variable name (`hasAcceptedTerms`) and the most suitable data type (Boolean) for a true/false condition, as described in the content. This enhances readability and proper data representation.
A) 5
B) 10
C) 15
D) An error occurs.
Correct Answer: C
The assignment operator first evaluates the expression on the right. `num1 + num2` evaluates to `5 + 10`, which is 15. Then, this result (15) is assigned to `num1`, overwriting its previous value.
A) The data type
B) The assignment operator
C) The variable name
D) The data storage
Correct Answer: B
The content clearly states, 'The assignment operator allows a program to change the value represented by a variable.'
A) 1
B) 2
C) a
D) b
Correct Answer: A
The line `c ← a` assigns a copy of the current value of `a` (which is 1) to `c`. In the next line, `a` is updated to the value of `b` (which is 2). This change to `a` does not affect `c`, which holds the value `a` had at the moment of assignment. Therefore, `c` remains 1.
A) The variable's value can never be known.
B) The variable represents a value without showing the details of its storage.
C) The variable can only hold abstract concepts, not numbers.
D) The variable is a temporary placeholder that is deleted after use.
Correct Answer: B
An abstraction in programming hides complexity. By stating a variable is an abstraction that can hold a value and has associated data storage, the text implies that the programmer can use the variable to represent the value without needing to know the specific memory address or hardware details of where it is stored.
A) Strings cannot contain decimal points.
B) Using a number type allows for mathematical calculations like adding tax.
C) Number types use less memory than string types.
D) The assignment operator only works with number types.
Correct Answer: B
The text states that 'Some values are better suited to representation using one type of datum rather than another.' While you could store '19.99' as a string, representing it as a number is better because it allows the program to perform mathematical operations on the price, which is a common requirement for such a value.