Back to computer sciencecomputing use cases

Computer ScienceComputingMiddle schoolKey Stage 3

How to teach pseudocode

Pseudocode is a plan for a program written in plain English, one step per line. This page explains what students need to get right in pseudocode, with a free activity where Sparky turns each student's pseudocode for a game rule into Python they can run.

Title card reading 'How to teach pseudocode', next to three chat cards: a student writes 'then you lose and start over', Sparky's Python marks that line with a comment saying Python doesn't know what start over means, and the student rewrites it as setting hearts to 3 and position to 0.

"Flint AI Tutor helped students with their Problem Statement Development. It helped them by identifying problem identification skills and focusing on data and facts to support their problem."

Anthony "Tony" CesaranoAnthony "Tony" Cesarano, Upper School Engineering and Computer Science Teacher

Why this matters

A student who can explain a game rule out loud can still write pseudocode that skips steps, like "then you lose and start over". A person reading that line fills in the missing steps without noticing, and a computer can't. On a worksheet the gap is easy to miss, and the teacher has to wait until the student's program breaks to find out which steps the plan left out.

What pseudocode is

Pseudocode describes the steps of an algorithm in plain language mixed with programming ideas such as assignment, conditions and loops. It is written for people to read, so it often leaves out details a computer needs (Wikipedia). The CSTA K-12 Computer Science Standards ask students in grades 6 to 8 to "use flowcharts and/or pseudocode to address complex problems as algorithms" (standard 2-AP-10, CSTA).

Pseudocode that a programmer can turn straight into code has three features that students' first drafts often lack.

  • Each line is one action, and the action says what changes, such as "set hearts to 3" instead of "start over".
  • Every condition can be checked, such as "if hearts is 0" instead of "if hearts are gone".
  • Indentation shows which steps belong inside an if or a loop.

In the Flint activity, each student writes a rule from a game they play as pseudocode, and Sparky turns each line into Python, exactly as written, that the student runs in Flint's code editor. A worksheet can mark a step as unclear, and Sparky shows the student what a computer does with it by leaving a comment on each vague line saying Python doesn't know what it means.

Sparky shows Owen the steps his pseudocode skipped

Owen ends up rewriting two vague steps as lines that say what changes, then traces what three hits in a row do. Every student gets the same activity, and Sparky's replies depend on each student's own pseudocode.

Sparky uses Owen's own words and gameSparky sends Owen back to his own line or codeA right answer gets a harder question
O

Owen

Interest: Platformer games with three heartsStarting point: Writes steps a person would fill in

Sparky

Today you're the programmer and I'm the computer. I do exactly what you tell me, nothing more.
An interactive Sparky attached to its first message. A coin game rule is written as four pseudocode lines, and the Python version beside it indents each line under its if. Line 4 reads: # ??? Python doesn't know what 'win' means, and a yellow note says the computer needs a step: what changes, or what gets shown, when the player wins.
InteractivePseudocode → Python: See How It Works

Owen

when player gets hit by enemy
lose a heart
if hearts are gone
then you lose and start over

Sparky

Here's your pseudocode turned into Python, line by line, exactly as you wrote it. I left a # ??? comment because Python doesn't know what "start over" means.
Owen's rule as Python in Flint's code editor: hearts starts at 3, goes down by 1, and if hearts equals 0 the program prints you lose, followed by the comment # ??? Python doesn't know what start over means. The Output panel shows 2 after Execute was pressed.
CodeOwen's hearts rule, first version

Owen

start over means you go back to the beginning of the level

Sparky

Good thinking, but "go back to the beginning of the level" is still something I (the computer) don't automatically know how to do. Looking at your code, what variable tracks how the player is doing?

Owen

oh the hearts have to go back to 3 or you'd lose again right away
if hearts is 0
say game over
set hearts to 3
set player position to 0

Understanding check

No # ??? comments this time. Edge-case challenge: what happens if the player gets hit 3 times in a row?

Owen

hit 1 hearts go to 2, hit 2 hearts go to 1, hit 3 hearts go to 0 so it says game over, hearts go back to 3 and position goes to 0.

Found two steps his pseudocode skipped and traced three hits

Owen is an example student, and Sparky's replies are shortened.

What Flint did for Owen

  • Sparky turned Owen's pseudocode into Python line by line and marked "start over" with a comment instead of guessing.
  • When Owen's rewrite stayed vague, Sparky pointed him back to his own code, and Owen wrote the reset himself.
  • Once every line was clear, Sparky asked what three hits in a row would do, and Owen traced each one.

A teacher can't do this by hand for 30 students, and Sparky does it in every student's chat.

The activity page shows whose pseudocode still skips steps

While the class works, Needs attention shows the teacher which student is stuck and on which message. After three or more students submit, activity analytics lists what the class explained well, where students went wrong, and a follow-up to practice next.

Flint's activity page for the pseudocode game rules activity. Needs attention shows one student who has rewritten 'then you win' three times without saying what changes. Activity analytics says 8 students wrote conditions the computer can't check, like 'if hearts are gone', and suggests rewriting vague steps like 'start over' as lines that each change one variable. The Sessions table lists three students.

Example activity page

After a computer science class writes their game rules

The school and students are made up for this page.

Set up the activity for free

The pseudocode activity is in Flint's public library, with the coin game interactive, Sparky's guidelines and the greeting already written. Open it, select Use activity to copy it into a free Flint account, and assign it to a class. Students write their pseudocode in the chat and press Execute in Flint's code editor to run the Python Sparky writes back.

For more computer science activities, see Flint for computer science.

Other use cases

See all use cases →

Learning feels different when it fits you.