Pseudocode Examples in CS Thinking

Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Pseudocode.

This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.

Concept Recap

An informal, human-readable description of an algorithm using structured language that resembles code but isn't tied to any specific programming language.

Pseudocode is a rough draft for code โ€” write the logic in plain English first, then translate to real code.

Read the full concept explanation โ†’

How to Use These Examples

  • Read the first worked example with the solution open so the structure is clear.
  • Try the practice problems before revealing each solution.
  • Use the related concepts and background knowledge badges if you feel stuck.

What to Focus On

Core idea: Pseudocode lets you focus on logic without worrying about syntax. It's a planning tool, not a running program.

Common stuck point: There's no single 'correct' pseudocode format. It just needs to be clear and unambiguous to the reader.

Worked Examples

Example 1

easy
Write pseudocode for a program that asks the user for two numbers and outputs the larger one.

Solution

  1. 1
    Step 1: Get the inputs: a = INPUT('Enter first number'). b = INPUT('Enter second number').
  2. 2
    Step 2: Compare: IF a > b THEN OUTPUT a. ELSE OUTPUT b.
  3. 3
    Step 3: Pseudocode does not follow the syntax of any specific language โ€” it uses plain English-like statements to describe the logic clearly.

Answer

INPUT a, b. IF a > b THEN OUTPUT a ELSE OUTPUT b. Pseudocode describes logic without language-specific syntax.
Pseudocode is an informal way of describing an algorithm using structured English. It focuses on logic rather than syntax, making it accessible to anyone regardless of programming language knowledge.

Example 2

medium
Convert the following Python code to pseudocode: total = 0; for i in range(1, 11): if i % 2 == 0: total += i; print(total).

Practice Problems

Try these problems on your own first, then open the solution to compare your method.

Example 1

medium
Write pseudocode for a program that reads a list of 10 numbers and outputs how many are above average.

Example 2

hard
A colleague writes pseudocode that mixes Python syntax, uses unclear variable names, and skips steps. Identify three problems with: 'x = input(); for y in x: if y == z: cnt+=1; print(cnt)'. Rewrite it properly.

Background Knowledge

These ideas may be useful before you work through the harder examples.

algorithm