CodeBlanks Logo Icon CodeBlanks

Pseudocode

Learn to write algorithm steps in readable pseudocode.

What is pseudocode?

Pseudocode writes algorithm steps in a human-readable form. It expresses the logic without being bound to a real programming language's syntax.

It uses constructs like if, for, while but details like declarations or semicolons are flexible.

Pseudocode examples

Pseudocode for the larger of two numbers: if a > b: return a else: return b. This checks a condition and picks a branch.

Pseudocode shows steps in order and clearly. You can translate the same logic into Python, Java or C++ code easily.

Practice Find maximum

Write max_of_two(a, b). Return a if a > b, else b. Print 9 with print(max_of_two(4, 9)).

Starter code

solution.py
def max_of_two(a, b):
    # Find the larger

Sample solution

solution.py
def max_of_two(a, b):
    # Find the larger
    if a > b:
        return a
    else:
        return b
print(max_of_two(4, 9))

Expected output

9

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Pseudocode: match the terms

Term Meaning
if Condition
for Loop
return Result
while Repeat

2 What is the purpose of pseudocode?

  • Run by machine
  • Generate a compiler
  • Understood by humans Correct answer
  • Compress files

Explanation: Pseudocode is for humans to understand.

3 Decision structure

Question
A condition in an algorithm: ____ a > b then return a
Answer
A condition in an algorithm: if a > b then return a

Explanation: if is right.

All lessons in Beginner