Computer Science Principles Exam Prep

AP Computer Science Principles pseudocode: how the exam writes code

The exam writes code in its own pseudocode, and a reference sheet is provided. Lists start at index 1, and REPEAT UNTIL stops when its condition becomes true.

Assignmenta ← expression
ListsIndexed from 1; an index outside the list is an error
Division17 / 5 is 3.4; 17 MOD 5 is 2

The rules that cost points

  • DISPLAY shows a value followed by a space.
  • INSERT and REMOVE shift the later items.
  • RANDOM(a, b) includes both a and b.
  • A robot that moves into a blocked square or off the grid stops the program.

Try a question

Question 1
What is displayed as a result of running the code segment?pets ← ["cat", "dog", "fish", "dog", "bird"] pos ← 0 i ← 1 FOR EACH p IN pets { IF (p = "dog") { pos ← i } i ← i + 1 } DISPLAY(pos)

Next step

Questions people ask

Do you get a reference sheet on the AP Computer Science Principles exam?

Yes. It shows the exam's pseudocode for assignment, display, arithmetic, conditions, loops, lists, procedures and the robot.

Are lists in AP Computer Science Principles indexed from 0 or 1?

From 1. The first item of aList is aList[1].