Unit 3: Programming · What is programming?

Article

Reading AP pseudocode

6 min read

Some students learn Python. Some learn Java. Some learn JavaScript. On exam day, all of them must read the same questions. So the AP exam does not use any real language. It uses its own notation, and this article teaches you to read it.

What pseudocode is

Pseudocode is a way to write the steps of a program that looks like code but is not tied to one programming language. A computer cannot run it. People read it. It describes what a program does in a clear, exact way.

The AP exam uses one pseudocode, the same for everyone. You have already seen it. Here is one small program in both forms:

AP pseudocode
width ← 4
height ← 3
area ← width * height
DISPLAY(area)
Runs in your browser

Both programs do the same thing. They store 4 and 3, multiply them, and show 12. Only the spelling is different. Real programming languages are all different from each other in small ways like this, but the ideas underneath are the same. Once you understand the ideas, you can read any of them.

Check your understanding

Why does the AP exam use its own pseudocode?

The same idea, written two ways

These are the differences you need now. Learn them well, because the exam uses the AP form and you will use Python to practise.

IdeaAP pseudocodePython
Store a value in a variablex ← 5x = 5
Show a valueDISPLAY(x)print(x)
Remainder of a divisiona MOD ba % b
Add, subtract, multiply+ - *+ - *

The arrow ← means "gets": x ← 5 says "x gets the value 5". Python uses the plain = sign for the same job. You will study variables in the next lesson.

Later lessons add more rows. Look at this preview now, so that nothing surprises you later. You do not need to learn it yet.

IdeaAP pseudocodePython
Test if two values are equala = ba == b
Test if they are differenta ≠ ba != b
DecisionIF(a > b) { ... }if a > b:
Repeat 3 timesREPEAT 3 TIMES { ... }for i in range(3):
First item of a listmyList[1]myList[0]

Two of these cost students marks every year. In AP pseudocode = asks a question ("are these equal?") and ← stores a value. And AP lists start counting at 1, while Python lists start at 0.

Check your understanding

Which Python statement does the same job as DISPLAY(7)?

The reference sheet

On exam day you get a reference sheet. It lists every command the exam uses and says what each one does. You do not have to memorise the notation, but you must be fast at reading it. Some questions show the same code as coloured blocks, like in Scratch, instead of text. The meaning of the blocks and the text is the same.

On the AP exam you read pseudocode. You are not asked to write it in the multiple-choice questions.

Reading code like the computer

To read any pseudocode, move down the lines one at a time and say each in plain English:

  1. width ← 4 says "width gets 4".
  2. height ← 3 says "height gets 3".
  3. area ← width * height says "area gets width times height", which is 12.
  4. DISPLAY(area) says "show area", so the screen shows 12.

If you read it this way, a long program is only a list of short, simple sentences.

Worked example: from Python to AP pseudocode

Here is a Python program. Rewrite it in AP pseudocode and say what it displays.

price = 20
extra = 5
total = price + extra
print(total)

Change the = signs to ← and change print to DISPLAY:

AP pseudocode
price ← 20
extra ← 5
total ← price + extra
DISPLAY(total)

Trace it: price is 20, extra is 5, total is 25, and the program shows 25.

Common mistakes

  • Using = to store a value in AP pseudocode. The exam uses ← for storing. In AP pseudocode, = compares two values.
  • Using ← in Python. Python does not know the arrow. It uses =.
  • Writing print in pseudocode, or DISPLAY in Python. Each language has its own word. Python also cares about capital letters: Print and print are different.
  • Thinking pseudocode is "not real". It is exact. Every symbol has one meaning, and the exam questions depend on it.
  • Guessing instead of reading. If a command looks strange, find it on the reference sheet. Do not guess what it does.

On the exam

Every programming question uses AP pseudocode. If you practise in Python, remember to translate: ← for =, DISPLAY for print, MOD for %. Answer from the pseudocode's rules, not from Python's. A question may even look a little like Python and behave differently, such as lists that start at 1.

Key words

Pseudocode: a way to write the steps of a program that looks like code but is not tied to one language.

AP pseudocode: the notation used on the AP exam.

Reference sheet: the page given in the exam that lists every command and what it does.

Assignment arrow ←: the AP symbol that stores a value in a variable.

Python: a real programming language that you can run.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse, this site. All lessons and questions here are written by JrCodex.