AP Computer Science Principles Practice Exam Notes
Exam Content and Format
- The AP Computer Science Principles Exam has two parts:
- Create performance task (at least 12 hours of class time).
- End-of-course AP Exam: 2 hours, 70 multiple-choice questions.
Administering the Practice Exam
- Instructions for administering the practice exam are provided.
- Exam materials needed: test booklets and answer sheets.
- Instructions for students:
- 2 hours to answer 70 multiple-choice questions.
- Questions 1-62: select the single best answer.
- Questions 131-138: select the two best answer choices.
- Total score based only on the number of questions answered correctly. No points deducted for incorrect or unanswered questions.
- Eliminate choices when unsure and select the best among remaining.
- Checking work is allowed if time permits.
- Programming reference materials are located at the front of the exam.
- Reference materials provide instructions and explanations to help understand the format and meaning of the questions.
Reference Materials
- Programming instructions use four data types: numbers, Booleans, strings, and lists.
- Instructions may include:
- Assignment, Display, and Input
- Arithmetic Operators and Numeric Procedures
- Relational and Boolean Operators
- Selection
- Iteration
- List Operations
- Procedures and Procedure Calls
- Robot
Assignment, Display, and Input
- Assignment
- Text:
a ← expression - Block: [Block diagram of assignment]
- Evaluates the expression and assigns a copy of the result to variable
a.
- Text:
- Display
- Text:
DISPLAY(expression) - Block: [Block diagram of display]
- Displays the value of the expression, followed by a space.
- Text:
- Input
- Text:
INPUT() - Block: [Block diagram of input]
- Accepts a value from the user and returns the input value.
- Text:
Arithmetic Operators and Numeric Procedures
- Arithmetic Operators
- Text and Block:
a + b,a - b,a * b,a / b - Perform arithmetic on
aandb. - Example:
17 / 5evaluates to3.4. - Order of operations applies.
- Text and Block:
- MOD Operator
- Text and Block:
a MOD b - Evaluates to the remainder when
ais divided byb. ais an integer >= 0,bis an integer > 0.- Example:
17 MOD 5evaluates to2. - Precedence is the same as
*and/.
- Text and Block:
- RANDOM Procedure
- Text:
RANDOM(a, b) - Block: [Block diagram of random]
- Generates and returns a random integer from
atob(inclusive). - Each result is equally likely.
- Example:
RANDOM(1, 3)could return 1, 2, or 3.
- Text:
Relational and Boolean Operators
- Relational Operators
- Text and Block:
a = b,a ≠ b,a > b,a < b,a ≥ b,a ≤ b - Test the relationship between two variables, expressions, or values.
- Evaluates to a Boolean value (true or false).
- Example:
a = bis true ifaandbare equal, otherwise false.
- Text and Block:
- NOT Operator
- Text:
NOT condition - Block: [Block diagram of not]
- Evaluates to
trueifconditionisfalse; otherwise, evaluates tofalse.
- Text:
- AND Operator
- Text:
condition1 AND condition2 - Block: [Block diagram of and]
- Evaluates to
trueif bothcondition1andcondition2aretrue; otherwise, evaluates tofalse.
- Text:
- OR Operator
- Text:
condition1 OR condition2 - Block: [Block diagram of or]
- Evaluates to
trueifcondition1istrue, or ifcondition2istrue, or if both aretrue; otherwise evaluates tofalse.
- Text:
Selection
IF Statement
- Text:
IF(condition) { <block of statements> }- Block: [Block diagram of if]
- Code in the block of statements is executed if the Boolean expression
conditionevaluates totrue; no action ifconditionisfalse.
IF-ELSE Statement
- Text:
IF(condition) { <first block of statements> } ELSE { <second block of statements> }- Block: [Block diagram of if-else]
- Code in the first block is executed if
conditionistrue; otherwise, code in the second block is executed.
Iteration
REPEAT n TIMES
- Text:
REPEAT n TIMES { <block of statements> }- Block: [Block diagram of repeat n times]
- Code in the block of statements is executed
ntimes.
REPEAT UNTIL (condition)
- Text:
REPEAT UNTIL(condition) { <block of statements> }- Block: [Block diagram of repeat until]
- Code in the block of statements is repeated until the Boolean expression
conditionevaluates totrue.
List Operations
If a list index is out of bounds (less than 1 or greater than the length of the list), an error occurs and the program terminates.
List Creation
- Text:
aList ← [value1, value2, value3, ...] - Block: [Block diagram of list creation]
- Creates a new list with the given values at indices 1, 2, 3, … and assigns it to
aList.
- Text:
Empty List Creation
- Text:
aList ← [] - Block: [Block diagram of empty list creation]
- Creates an empty list and assigns it to
aList.
- Text:
List Copy
- Text:
aList ← bList - Block: [Block diagram of list copy]
- Assigns a copy of list
bListto listaList. - Example: If
bListis[20, 40, 60], thenaListwill also be[20, 40, 60].
- Text:
Access Element at Index
- Text:
aList[i] - Block: [Block diagram of access element]
- Accesses the element of
aListat indexi. - The first element is at index 1 (
aList[1]).
- Text:
Assign Value from List
- Text:
x ← aList[i] - Block: [Block diagram of assign value from list]
- Assigns the value of
aList[i]to the variablex.
- Text:
Assign Value to List
- Text:
aList[i] ← x - Block: [Block diagram of assign value to list]
- Assigns the value of
xtoaList[i].
- Text:
Assign Value from List to Another Index
- Text:
aList[i] ← aList[j] - Block: [Block diagram of assign value list to another index]
- Assigns the value of
aList[j]toaList[i].
- Text:
Insert Value
- Text:
INSERT(aList, i, value) - Block: [Block diagram of insert value]
- Shifts values at indices >=
ione position to the right. - Increases the length of the list by 1.
- Places
valueat indexiinaList.
- Text:
Append Value
- Text:
APPEND(aList, value) - Block: [Block diagram of append value]
- Increases the length of
aListby 1. - Places
valueat the end ofaList.
- Text:
Remove Value
- Text:
REMOVE(aList, i) - Block: [Block diagram of remove value]
- Removes the item at index
iinaList. - Shifts values at indices >
ito the left. - Decreases the length of
aListby 1.
- Text:
Length of List
- Text:
LENGTH(aList) - Block: [Block diagram of length of list]
- Evaluates to the number of elements in
aList.
- Text:
For Each Item in List
- Text:
FOR EACH item IN aList { <block of statements> }- Block: [Block diagram of for each item in list]
- The variable
itemis assigned the value of each element ofaListsequentially (from first to last). - The code in the block of statements is executed once for each assignment of
item.
Procedures and Procedure Calls
Procedure Definition
- Text:
PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> }- Block: [Block diagram of procedure definition]
- Defines
procNameas a procedure that takes zero or more arguments. - The procedure contains a block of statements.
procNamecan be called asprocName(arg1, arg2, ...)(wherearg1is assigned toparameter1,arg2toparameter2, etc.).
Procedure Definition with Return
- Text:
PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) }- Block: [Block diagram of definition with return]
- Defines
procNameas a procedure that takes zero or more arguments. - The procedure contains a block of statements and returns the value of
expression. RETURNmay appear at any point inside the procedure, causing an immediate return to the calling statement.- The value returned can be assigned as
result ← procName(arg1, arg2, ...).
Return Statement
- Text:
RETURN(expression) - Block: [Block diagram of return]
- Returns flow of control to the point where the procedure was called and returns the value of
expression.
- Text:
Robot
- If the robot attempts to move to a square that is not open or is beyond the edge of the grid, the robot will stay in its current location and the program will terminate.
- MOVE_FORWARD()
- Block: [Block diagram of move forward]
- The robot moves one square forward in the direction it is facing.
- ROTATE_LEFT()
- Block: [Block diagram of rotate left]
- The robot rotates in place 90 degrees counterclockwise (left turn).
- ROTATE_RIGHT()
- Block: [Block diagram of rotate right]
- The robot rotates in place 90 degrees clockwise (right turn).
- CAN_MOVE(direction)
- Block: [Block diagram of can move]
- Evaluates to
trueif there is an open square one square in thedirectionrelative to where the robot is facing; otherwise, evaluates tofalse. directioncan beleft,right,forward, orbackward.