Grade by Grade
B. Software Development · Software Development: Problem Solving, Design, Testing and the Life Cycle

Designing with Flow Charts and Pseudocode

B2.4 B2.2About 70 minutes
Learning goals
  • I can name and draw the standard flow chart symbols.
  • I can draw a flow chart for a program with sequence, selection (decisions) and repetition (loops).
  • I can write clear pseudocode for an algorithm and translate pseudocode into Python.
  • I can read a flow chart or pseudocode and predict its output.

Words to know

flow chart
A diagram that shows the steps of an algorithm as standard shapes joined by arrows, in the order they happen.
terminator
The rounded (oval) symbol that marks Start and End.
decision symbol
The diamond that asks a yes/no question. It has one arrow in and two arrows out (yes and no).
input/output symbol
The parallelogram used for INPUT and OUTPUT steps.
pseudocode
A structured, plain-language description of an algorithm that looks like code but follows no exact language rules.
sequence, selection, repetition
The three basic control structures: steps in order, choosing between paths, and repeating steps.

A blueprint before you build

Nobody builds a house without a blueprint. Programmers make blueprints too. The two most common ones for an algorithm are flow charts (pictures) and pseudocode (structured words).

Both let you design and check your logic before you worry about colons, brackets and spelling. They also let you describe a design to someone who does not know Python, such as a client or a teammate who uses a different language. In the next lesson you will meet tools that show a whole program's structure (structure charts, data flow diagrams and UML). Today is about the steps inside an algorithm.

Flow chart symbols

Flow charts use a small set of standard shapes. Using the standard shapes means anyone in the industry can read your chart.

Start / EndterminatorINPUT ageinput / outputtotal = 0processage < 13?decisionget_tax()predefined process(subprogram)Aconnectorflow line
The standard flow chart symbols. Each kind of step has its own shape, and arrows (flow lines) show the order. A connector joins two parts of a chart that are far apart or on different pages.

Rules for a tidy flow chart:

  • Exactly one Start and at least one End.
  • Flow goes top to bottom (and left to right) wherever possible.
  • A decision diamond asks a question with a yes/no answer and has two labelled exits.
  • Every shape except End has an arrow out. No arrow ever leads nowhere.
  • A loop appears as an arrow that goes back up to an earlier step.
Worked example

Example 1: A flow chart with decisions (selection)

A community cinema charges $9 for children under 13, $10 for seniors 65 and over, and $14 for everyone else. Draw a flow chart, then write the Python.

  1. Start, then INPUT the age (parallelogram).
  2. First decision: age < 13? If yes, price = 9.
  3. If no, second decision: age >= 65? If yes, price = 10; if no, price = 14.
  4. All three paths join before OUTPUT price, then End.
  5. In Python, two decisions in a row become if / elif / else.

The flow chart is below. For an age of 70 the program prints Ticket: $10.00.

StartINPUT ageage < 13?price = 9age >= 65?price = 10price = 14OUTPUT priceEndyesnoyesno
Flow chart for the cinema ticket price. Each diamond has a yes exit and a no exit, and all three prices lead to the same OUTPUT step.
age = int(input("Age: "))
if age < 13:
price = 9
elif age >= 65:
price = 10
else:
price = 14
print(f"Ticket: ${price:.2f}")

Sample run: the user types 70. Output: Ticket: $10.00. Try 12 (expect $9.00), 13 (expect $14.00), 64 and 65 too.

Loops in flow charts

A loop is drawn as a decision whose yes (or no) path leads back up to an earlier step. The chart below reads numbers and keeps a running total until the user types 0. The value 0 is called a sentinel: a special value that means "stop".

Starttotal = 0INPUT numnum != 0?total = total + numINPUT numOUTPUT totalEndyesnoloop back
A sentinel loop. While the number is not 0, it is added to the total and a new number is read; the arrow on the left carries the flow back up to the decision.
total = 0
num = int(input("Number (0 to stop): "))
while num != 0:
total = total + num
num = int(input("Number (0 to stop): "))
print("Total:", total)

Sample run: the user types 5, 8 and then 0. Output: Total: 13. Notice the input step appears twice, once before the loop and once at the end of it, exactly as in the flow chart.

Pseudocode

Pseudocode describes an algorithm in structured English. There is no single official standard, but most courses follow these conventions:

  • Keywords in capitals: INPUT, OUTPUT (or DISPLAY), SET ... TO, IF ... THEN ... ELSE ... END IF, WHILE ... END WHILE, FOR ... END FOR.
  • Indent the steps inside a decision or loop.
  • One step per line, with meaningful names.
  • No language details: no colons, no int(), no brackets unless they help.

Good pseudocode is precise enough that two different programmers would write programs that behave the same way.

SET largest TO the first mark in marks
FOR EACH mark IN marks
IF mark > largest THEN
SET largest TO mark
END IF
END FOR
OUTPUT largest

Pseudocode for finding the largest mark in a list. It is not Python, so it will not run, but it translates line by line.

Worked example

Example 2: From pseudocode to Python

Translate the pseudocode above into Python and test it on the marks 68, 91, 77 and 85.

  1. SET largest TO the first mark becomes largest = marks[0] (the first item of the list).
  2. FOR EACH mark IN marks becomes for mark in marks:.
  3. IF mark > largest THEN becomes if mark > largest: and the indented line updates largest.
  4. END IF and END FOR have no Python line: indentation ends the block.
  5. OUTPUT largest becomes print(...). Trace: largest starts 68, becomes 91 at the second mark, and stays 91.

The program prints Largest: 91.

marks = [68, 91, 77, 85]
largest = marks[0]
for mark in marks:
if mark > largest:
largest = mark
print("Largest:", largest)

Output: Largest: 91

PseudocodePython
INPUT nn = int(input("n: "))
SET total TO 0total = 0
IF x > 0 THEN ... ELSE ... END IFif x > 0: ... else: ...
WHILE guess != secret ... END WHILEwhile guess != secret:
FOR i FROM 1 TO 10 ... END FORfor i in range(1, 11):
OUTPUT "Done"print("Done")
Translating common pseudocode lines into Python. Watch the FOR loop: FROM 1 TO 10 includes 10, but Python's range stops one before its end value.

Flow chart or pseudocode?

  • Flow charts are best for showing branching and looping visually, and for explaining to non-programmers. They get large and messy for long programs.
  • Pseudocode is compact, easy to edit, and close to real code. It is better for longer algorithms.

Many teams sketch a flow chart for tricky logic and use pseudocode for the rest.

Just for fun

Shampoo bottles say: Lather. Rinse. Repeat. A computer following those instructions exactly would never leave the shower. There is no decision diamond to stop the loop!

Hands-on activity

Flow-chart your morning

You need: paper, a pencil, and (optional) sticky notes in three colours.

  1. Draw a flow chart for getting ready on a winter school morning. Include at least two decisions (for example "Is it snowing?" → wear boots; "Is the bus late?") and one loop (for example "Repeat: press snooze, while it is earlier than 7:00").
  2. Use the correct shapes. If you have sticky notes, use one colour per shape type and stick them on a table to rearrange easily.
  3. Give your chart to a family member to "run" with different conditions. Did every path reach End?
  4. Rewrite your chart as pseudocode with IF ... END IF and WHILE ... END WHILE.

What to look for: diamonds with two labelled exits, one Start, every path ending at End, a loop arrow going back up, and pseudocode that matches the chart.

Your turn

1

Which flow chart symbol is used for a yes/no question? For an INPUT step?

2

In the cinema flow chart, what price is output for an age of 13? For 65?

3

Write pseudocode for: read a temperature; if it is below 0, output "Wear a toque"; otherwise output "No toque needed".

4

In the sentinel loop program, what is printed if the user types 4, 4, 4, 0?

5

What is printed if the very first number typed in the sentinel program is 0?

6

Translate into Python: FOR i FROM 1 TO 5 / OUTPUT i × i / END FOR. What is the output?

7

A student's flow chart has a diamond with only one arrow coming out. What is wrong?

More practice: warm-up

1

Which symbol marks Start and End?

2

Which symbol is used for total = total + num?

3

What is pseudocode?

4

What are the three basic control structures?

5

What is a sentinel value?

More practice: on your own

1

Write pseudocode for a program that reads 5 marks and outputs how many are 50 or more.

2

Describe (in words) the flow chart for a number-guessing game: the secret number is 7; the user keeps guessing until correct; then the program outputs "Got it!".

3

Trace this pseudocode and give the output: SET n TO 1 / WHILE n < 50 / SET n TO n × 3 / END WHILE / OUTPUT n.

4

Translate the pseudocode in the previous question into Python.

5

Give one advantage of a flow chart over pseudocode and one advantage of pseudocode over a flow chart.

Challenge

1

Write pseudocode for a program that reads whole numbers until the sentinel −1 and then outputs the smallest number read. Make sure it works if the first number is −1.

2

A flow chart has this logic: INPUT x; decision x > 10? yes → decision x > 20? yes → OUTPUT "big"; no → OUTPUT "medium". From the first diamond, no → OUTPUT "small". What is output for x = 10, 15 and 20?

3

Write Python for the leap-year rule in this pseudocode, then test 2024, 2026 and 1900: IF year divisible by 400 THEN leap / ELSE IF year divisible by 100 THEN not leap / ELSE IF year divisible by 4 THEN leap / ELSE not leap.

Check your understanding

Quiz

1.

Which flow chart symbol represents a decision?

2.

How is a loop shown in a flow chart?

3.

What does this pseudocode output? SET x TO 2 / WHILE x < 20 / SET x TO x × 2 / END WHILE / OUTPUT x

4.

FOR i FROM 1 TO 10 translates to which Python line?

5.

Which statement about pseudocode is true?

6.

In the cinema example, what is the price for a 12-year-old?

For parents and teachers

Big idea: B2.4 asks students to represent programs with industry-standard tools including flow charts and pseudocode; B2.2 asks them to describe designs in diagrammatic and written modes. These skills are tested on paper as often as at the keyboard.

How to help: Ask your teen to "run" their flow chart with you: you choose the inputs and follow the arrows with your finger. If you get lost or reach a dead end, the chart has a problem. The morning-routine flow chart is a fun way to practise.

Common difficulties:

  • Using the wrong shapes (especially a rectangle for input or output).
  • Diamonds with one exit, or unlabelled yes/no exits.
  • Pseudocode that is really just Python (or just vague English). It should be structured but language-independent.
  • Off-by-one translations: FOR i FROM 1 TO 10 needs range(1, 11) in Python.