B. Software Development · Software Development: Problem Solving, Design, Testing and the Life CycleDesigning 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.
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 exampleExample 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.
- Start, then INPUT the age (parallelogram).
- First decision: age < 13? If yes, price = 9.
- If no, second decision: age >= 65? If yes, price = 10; if no, price = 14.
- All three paths join before OUTPUT price, then End.
- 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.
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".
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 exampleExample 2: From pseudocode to Python
Translate the pseudocode above into Python and test it on the marks 68, 91, 77 and 85.
SET largest TO the first mark becomes largest = marks[0] (the first item of the list).FOR EACH mark IN marks becomes for mark in marks:.IF mark > largest THEN becomes if mark > largest: and the indented line updates largest.END IF and END FOR have no Python line: indentation ends the block.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
| Pseudocode | Python |
|---|
INPUT n | n = int(input("n: ")) |
SET total TO 0 | total = 0 |
IF x > 0 THEN ... ELSE ... END IF | if x > 0: ... else: ... |
WHILE guess != secret ... END WHILE | while guess != secret: |
FOR i FROM 1 TO 10 ... END FOR | for 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 funShampoo 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 activityFlow-chart your morning
You need: paper, a pencil, and (optional) sticky notes in three colours.
- 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").
- Use the correct shapes. If you have sticky notes, use one colour per shape type and stick them on a table to rearrange easily.
- Give your chart to a family member to "run" with different conditions. Did every path reach End?
- 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
1Which flow chart symbol is used for a yes/no question? For an INPUT step?
A diamond (decision). A parallelogram (input/output).
2In the cinema flow chart, what price is output for an age of 13? For 65?
13 is not < 13 and not ≥ 65, so $14. 65 ≥ 65, so $10.
3Write pseudocode for: read a temperature; if it is below 0, output "Wear a toque"; otherwise output "No toque needed".
INPUT temp / IF temp < 0 THEN / OUTPUT "Wear a toque" / ELSE / OUTPUT "No toque needed" / END IF (one per line, with the OUTPUT lines indented).
4In the sentinel loop program, what is printed if the user types 4, 4, 4, 0?
5What is printed if the very first number typed in the sentinel program is 0?
Total: 0. The loop condition is false at once, so the loop body never runs.
6Translate into Python: FOR i FROM 1 TO 5 / OUTPUT i × i / END FOR. What is the output?
for i in range(1, 6): then print(i * i). Output: 1, 4, 9, 16, 25 on separate lines.
7A student's flow chart has a diamond with only one arrow coming out. What is wrong?
A decision must have two exits, labelled yes and no. One path is missing, so the chart does not say what happens in the other case.
More practice: warm-up
1Which symbol marks Start and End?
The terminator (a rounded rectangle or oval).
2Which symbol is used for total = total + num?
A structured, plain-language description of an algorithm that looks like code but does not follow the exact rules of a programming language.
4What are the three basic control structures?
Sequence, selection and repetition.
5What is a sentinel value?
A special input value that signals the end of the data, such as 0 meaning "stop".
More practice: on your own
1Write pseudocode for a program that reads 5 marks and outputs how many are 50 or more.
SET count TO 0 / FOR i FROM 1 TO 5 / INPUT mark / IF mark >= 50 THEN SET count TO count + 1 END IF / END FOR / OUTPUT count.
2Describe (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!".
Start → INPUT guess → decision "guess = 7?" → no: OUTPUT "Try again" and an arrow back to INPUT guess → yes: OUTPUT "Got it!" → End.
3Trace this pseudocode and give the output: SET n TO 1 / WHILE n < 50 / SET n TO n × 3 / END WHILE / OUTPUT n.
n: 1 → 3 → 9 → 27 → 81. At 81 the condition n < 50 is false, so it outputs 81.
4Translate the pseudocode in the previous question into Python.
n = 1, then while n < 50: with the indented line n = n * 3, then print(n). It prints 81.
5Give one advantage of a flow chart over pseudocode and one advantage of pseudocode over a flow chart.
Flow chart: shows branches and loops visually, easy for non-programmers. Pseudocode: compact, fast to write and edit, and close to real code for long algorithms.
Challenge
1Write 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.
INPUT num / IF num = -1 THEN OUTPUT "No data" / ELSE / SET smallest TO num / WHILE num != -1 / IF num < smallest THEN SET smallest TO num END IF / INPUT num / END WHILE / OUTPUT smallest / END IF. The first IF handles the extreme case of no data.
2A 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?
x = 10: 10 > 10 is false → small. x = 15: > 10 yes, > 20 no → medium. x = 20: > 10 yes, 20 > 20 no → medium.
3Write 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.
One solution:
for year in [2024, 2026, 1900]: if year % 400 == 0: leap = True elif year % 100 == 0: leap = False elif year % 4 == 0: leap = True else: leap = False print(year, leap)
Output: 2024 True, 2026 False, 1900 False.
Check your understandingQuiz
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 teachersBig 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.