Computers — Python Programming
Revision Notes
Syllabus coverage: (a) Problem Solving & Algorithms — Top-Down Design, Structure Diagrams,
Pseudocode, Flowcharts, Trace Tables. (b) Python Programming — Conditional Statements, Iteration,
Functions.
A) Problem Solving & Algorithms
An algorithm is a clear, step-by-step set of instructions to solve a problem. Before writing code,
programmers plan the solution using design tools. This section covers the five key tools.
1. Top-Down Design (Stepwise Refinement)
Breaking a big problem into smaller, more manageable sub-problems. Each sub-problem is
broken down further until each part is simple enough to solve.
• Start with the whole problem at the top.
• Split it into sub-tasks (modules).
• Keep breaking down until each module does one job.
Why it's useful:
• Easier to understand and manage.
• Different people can work on different modules.
• Easier to test and debug each part separately.
2. Structure Diagram
A visual (graphical) way of showing top-down design. It looks like an upside-down tree showing
how a problem splits into sub-tasks across levels.
• Top box = the main problem.
• Boxes below = sub-tasks, connected by lines.
• Lower levels = more detailed steps.
Example — "Make a cup of tea" splits into: Boil water → Add tea bag → Add milk/sugar → Pour & serve.
3. Pseudocode
A way of planning code using simple, structured English. It is not a real programming language,
so there are no strict syntax rules — but it follows a logical structure close to code.
Common keywords:
INPUT / OUTPUT → get or show data
IF ... THEN ... ELSE ... ENDIF
FOR ... TO ... NEXT
WHILE ... ENDWHILE
Computers — Python Programming Notes • Page 1
REPEAT ... UNTIL
Example — output whether a number is positive:
INPUT number
IF number > 0 THEN
OUTPUT "Positive"
ELSE
OUTPUT "Not positive"
ENDIF
4. Flowchart
A diagram that shows the steps of an algorithm using standard symbols connected by arrows
showing the flow.
Symbol Shape Meaning
Terminator Rounded rectangle / oval Start or Stop
Process Rectangle A step / calculation
Input / Output Parallelogram Get input or show output
Decision Diamond A question with Yes/No
(branches)
Flow line Arrow Direction of the steps
Decisions create branches; loops are shown by an arrow going back up to a previous step.
5. Trace Table
A table used to test an algorithm by hand. You record how the values of variables change at
each step, which helps find logic errors (dry running).
Example — trace this loop:
total = 0
FOR count = 1 TO 3
total = total + count
NEXT count
OUTPUT total
count total OUTPUT
1 1
2 3
3 6 6
Computers — Python Programming Notes • Page 2
Quick Recap — Section A
Tool What it does
Top-Down Design Break a big problem into smaller parts
Structure Diagram Visual tree of the top-down breakdown
Pseudocode Plan logic in structured English
Flowchart Diagram of steps using symbols
Trace Table Test an algorithm by tracking variables
Computers — Python Programming Notes • Page 3
B) Python Programming
Python is a high-level programming language that is easy to read. This section covers three
core building blocks: conditional statements, iteration, and functions.
1. Conditional Statements (Selection)
Conditional statements let a program make decisions. Code only runs IF a condition is True.
Python uses if, elif (else-if), and else.
Comparison operators:
Operator Meaning
== equal to
!= not equal to
> / < greater than / less than
>= / <= greater/less than or equal to
Syntax & example:
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult")
elif age >= 13:
print("You are a teenager")
else:
print("You are a child")
• Indentation matters — Python uses spaces to know what's inside the if.
• Don't forget the colon ( : ) at the end of each line.
• Logical operators: and, or, not combine conditions.
2. Iteration (Loops)
Iteration means repeating a block of code. Python has two main loops: for and while.
for loop — count-controlled
Used when you know how many times to repeat. range(start, stop, step) generates the
numbers; stop is not included.
for i in range(1, 6):
print(i) # prints 1 2 3 4 5
Computers — Python Programming Notes • Page 4
while loop — condition-controlled
Used when you don't know how many repeats are needed. It keeps running while the condition
is True.
count = 1
while count <= 5:
print(count)
count = count + 1 # update or it loops forever!
Feature for loop while loop
Use when You know the count You don't know the count
Type Count-controlled Condition-controlled
Risk Low Infinite loop if not updated
3. Functions
A function is a named, reusable block of code that performs a task. You define it once and call it
whenever needed. This avoids repeating code (DRY — Don't Repeat Yourself).
Key terms:
• Define — create the function using def.
• Parameter — input listed in the definition.
• Argument — actual value passed in when calling.
• Return — sends a value back from the function.
Syntax & example:
def add(a, b): # a and b are parameters
result = a + b
return result
answer = add(3, 5) # 3 and 5 are arguments
print(answer) # output: 8
Why use functions:
• Reuse code without rewriting it.
• Makes programs shorter and easier to read.
• Easier to test and fix one piece at a time.
Quick Recap — Section B
Concept Keyword(s) Purpose
Conditionals if / elif / else Make decisions
Computers — Python Programming Notes • Page 5
Concept Keyword(s) Purpose
Iteration for / while Repeat code
Functions def / return Reusable blocks of code
Practice Questions
1. Draw a flowchart for an algorithm that inputs a number and outputs whether it is even or
odd.
2. Write a trace table for a FOR loop that adds the numbers 1 to 5.
3. Write Python code using a while loop to print the 5 times table.
4. Write a function called area that takes length and width and returns the area of a
rectangle.
5. Explain the difference between a parameter and an argument.
Computers — Python Programming Notes • Page 6