Module 18 · Algorithms and Problem Solving — topic 3 of 18
Flowcharts
Drawing algorithms as flowcharts: standard symbols for start/end, process, input/output and decisions, representing branches and loops, and translating a flowchart into Python.
Learning objectives
- Read and draw flowcharts with standard symbols
- Represent decisions and loops
- Convert a flowchart into Python code
Definition
A flowchart is a diagram of an algorithm using standard shapes connected by arrows: ovals for start and end, rectangles for processing steps, parallelograms for input and output, and diamonds for yes/no decisions.
Introduction
Before writing code, many programmers sketch the flow of a program on paper. A flowchart makes branches and loops visible at a glance.
Why it matters
Flowcharts help you think through logic, explain it to others and spot missing cases — such as what happens when the third PIN attempt fails.
Detailed explanation
An oval marks Start and End. Every flowchart has exactly one start.
A rectangle is a process step: a calculation or assignment such as total = total + price.
A parallelogram is input or output: read a number, display a result.
A diamond is a decision with a yes/no question; each answer leads along a labelled arrow. Decisions become if/elif/else in code.
An arrow that goes back to an earlier step forms a loop, which becomes a while or for loop in code.
Keep flowcharts top-to-bottom, label every decision branch, and avoid crossing lines where possible.
Each path through the flowchart is a scenario to test, which makes flowcharts useful for designing test cases.
For large programs, flowcharts become unwieldy; pseudocode and code structure then take over, but small flowcharts remain useful for tricky logic.
Syntax
- Ovals: start/end.
- Diamonds: decisions.
- Back-arrows: loops.
Code examples
A grading flowchart in text form
The same flowchart in Python
['A', 'B', 'C', 'F']
More examples
A loop with a limit: PIN attempts
attempt 1: wrong PIN access granted on attempt 2 attempt 1: wrong PIN attempt 2: wrong PIN attempt 3: wrong PIN card blocked
Step-by-step explanation
- In the flowchart, a decision 'PIN correct?' has a yes arrow to 'grant access' and a no arrow back to 'read PIN'.
- A second decision 'attempts < 3?' stops the loop; in code that is the slice attempts[:limit].
- The fourth PIN in the second call is never checked because the card is blocked first.
Expected output
Running “A loop with a limit: PIN attempts” prints exactly:
Practical applications
- Documenting business processes such as loan approval.
- Planning game logic and menu flows.
Best practices
- Use standard symbols consistently.
- Label every decision branch.
- Test each path through the chart.
Common mistakes
Unlabelled decision branches
Avoid
Prefer
Without labels, readers can't tell which path is which.
Important notes
- Tools such as draw.io and Mermaid can draw flowcharts from text.
Key takeaways
- Ovals start and end, rectangles process, parallelograms do I/O, diamonds decide.
- Back-arrows show loops.
- Each path is a test case.
Try it yourself
- 1Draw a flowchart for deciding whether a year is a leap year, then implement it.
- 2Draw a flowchart for a number-guessing game with five attempts.
Finished reading? Mark it complete to update your dashboard.
Suggested practice
16 questions cover the “Algorithms and Problem Solving” module. Answers and explanations are revealed after you submit.
- AdvancedWhat is printed?
- AdvancedWhat is the average time complexity of x in my_set?
- AdvancedA loop over a list checks item in other_list for each item. With both lists of length n, the complexity is…