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.
  • Display
    • Text: DISPLAY(expression)
    • Block: [Block diagram of display]
    • Displays the value of the expression, followed by a space.
  • Input
    • Text: INPUT()
    • Block: [Block diagram of input]
    • Accepts a value from the user and returns the input value.

Arithmetic Operators and Numeric Procedures

  • Arithmetic Operators
    • Text and Block: a + b, a - b, a * b, a / b
    • Perform arithmetic on a and b.
    • Example: 17 / 5 evaluates to 3.4.
    • Order of operations applies.
  • MOD Operator
    • Text and Block: a MOD b
    • Evaluates to the remainder when a is divided by b.
    • a is an integer >= 0, b is an integer > 0.
    • Example: 17 MOD 5 evaluates to 2.
    • Precedence is the same as * and /.
  • RANDOM Procedure
    • Text: RANDOM(a, b)
    • Block: [Block diagram of random]
    • Generates and returns a random integer from a to b (inclusive).
    • Each result is equally likely.
    • Example: RANDOM(1, 3) could return 1, 2, or 3.

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 = b is true if a and b are equal, otherwise false.
  • NOT Operator
    • Text: NOT condition
    • Block: [Block diagram of not]
    • Evaluates to true if condition is false; otherwise, evaluates to false.
  • AND Operator
    • Text: condition1 AND condition2
    • Block: [Block diagram of and]
    • Evaluates to true if both condition1 and condition2 are true; otherwise, evaluates to false.
  • OR Operator
    • Text: condition1 OR condition2
    • Block: [Block diagram of or]
    • Evaluates to true if condition1 is true, or if condition2 is true, or if both are true; otherwise evaluates to false.

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 condition evaluates to true; no action if condition is false.
  • 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 condition is true; 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 n times.
  • 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 condition evaluates to true.

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.
  • Empty List Creation

    • Text: aList ← []
    • Block: [Block diagram of empty list creation]
    • Creates an empty list and assigns it to aList.
  • List Copy

    • Text: aList ← bList
    • Block: [Block diagram of list copy]
    • Assigns a copy of list bList to list aList.
    • Example: If bList is [20, 40, 60], then aList will also be [20, 40, 60].
  • Access Element at Index

    • Text: aList[i]
    • Block: [Block diagram of access element]
    • Accesses the element of aList at index i.
    • The first element is at index 1 (aList[1]).
  • Assign Value from List

    • Text: x ← aList[i]
    • Block: [Block diagram of assign value from list]
    • Assigns the value of aList[i] to the variable x.
  • Assign Value to List

    • Text: aList[i] ← x
    • Block: [Block diagram of assign value to list]
    • Assigns the value of x to aList[i].
  • 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] to aList[i].
  • Insert Value

    • Text: INSERT(aList, i, value)
    • Block: [Block diagram of insert value]
    • Shifts values at indices >= i one position to the right.
    • Increases the length of the list by 1.
    • Places value at index i in aList.
  • Append Value

    • Text: APPEND(aList, value)
    • Block: [Block diagram of append value]
    • Increases the length of aList by 1.
    • Places value at the end of aList.
  • Remove Value

    • Text: REMOVE(aList, i)
    • Block: [Block diagram of remove value]
    • Removes the item at index i in aList.
    • Shifts values at indices > i to the left.
    • Decreases the length of aList by 1.
  • Length of List

    • Text: LENGTH(aList)
    • Block: [Block diagram of length of list]
    • Evaluates to the number of elements in aList.
  • 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 item is assigned the value of each element of aList sequentially (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 procName as a procedure that takes zero or more arguments.
    • The procedure contains a block of statements.
    • procName can be called as procName(arg1, arg2, ...) (where arg1 is assigned to parameter1, arg2 to parameter2, etc.).
  • Procedure Definition with Return

    • Text:
    PROCEDURE procName(parameter1, parameter2, ...) {
        <block of statements>
        RETURN(expression)
    }
    
    • Block: [Block diagram of definition with return]
    • Defines procName as a procedure that takes zero or more arguments.
    • The procedure contains a block of statements and returns the value of expression.
    • RETURN may 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.

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 true if there is an open square one square in the direction relative to where the robot is facing; otherwise, evaluates to false.
    • direction can be left, right, forward, or backward.