I1 · Python Programming for AI

Pseudocode and Flowcharts

Pseudocode is an algorithm written in structured plain language, using a few keywords such as IF, ELSE, WHILE and FOR, without the strict rules of a real programming language. A flowchart shows the same algorithm as a diagram, using standard shapes connected by arrows.

10 min Intermediate Jump to the activity

What you need: The earlier topics of this module.

Definition

How do you write steps any programmer, in any language, can follow?

Pseudocode is an algorithm written in structured plain language, using a few keywords such as IF, ELSE, WHILE and FOR, without the strict rules of a real programming language. A flowchart shows the same algorithm as a diagram, using standard shapes connected by arrows.

In simple words

Pseudocode is like a recipe written neatly: each line is one step, and indented lines belong to the step above. A flowchart is the same recipe as a map you can follow with your finger. Every algorithm is built from three ideas: sequence (do this, then that), selection (if this, do that) and repetition (do this again).

Why it matters

Teams plan programs in pseudocode and flowcharts before writing code, and exams and interviews use them to test thinking without language details. Once you can write pseudocode, turning it into Python is mostly translation.

How it works

Pass or fail, in pseudocode

READ mark
IF mark >= 40 THEN
    OUTPUT "Pass"
ELSE
    OUTPUT "Fail"
END IF
Flowchart shapeMeaning
Rounded rectangle (oval)Start or end
ParallelogramInput or output
RectangleA process step, such as a calculation
DiamondA decision with yes and no arrows
ArrowThe direction to go next

The three building blocks

  • Sequence: steps one after another.
  • Selection: IF … ELSE, a diamond in a flowchart.
  • Repetition: WHILE or FOR, an arrow that loops back.

Try it yourself

Match each shape to its meaning

Choose the meaning of each flowchart shape.

  • Diamond
  • Parallelogram
  • Rectangle
  • Oval

Turn a flowchart into pseudocode

The flowchart counts from 1 to 5. Put its pseudocode lines in order.

  1. 1SET count TO 1
  2. 2WHILE count <= 5
  3. 3 OUTPUT count
  4. 4END WHILE
  5. 5 SET count TO count + 1

Common mistakes

  • Writing pseudocode so vague that it is just prose.
  • Forgetting the 'no' arrow from a decision diamond.
  • Creating a loop that never ends because the counter never changes.

Check yourself

Question 1

1. Which flowchart shape shows a decision?

Question 2

2. Repetition in pseudocode uses…

Question 3

3. What are the three building blocks of every algorithm?

Summary

  • Pseudocode is structured plain language; flowcharts are the same steps as shapes.
  • Sequence, selection and repetition build every algorithm.
  • Good pseudocode translates almost line by line into Python.

Finished reading?