1. Planning with Algorithms and Pseudocode
Before writing any code, it's crucial to have a clear plan. An algorithm is a step-by-step set of instructions to solve a problem or complete a task. Think of it as a recipe for a computer. Pseudocode is a tool programmers use to write out these algorithms. It's not a real programming language, but a structured, English-like way to describe the steps a program will take. This allows you to focus on the logic of the solution without worrying about the specific syntax of a language like Python. A good pseudocode plan makes the actual coding process much faster and less error-prone.
Key term
Examiner insight
Common pitfall
Worked example 15 marks
A program is required to ask a user for two numbers, add them together, and display the result. Write the pseudocode for this algorithm.
- 1
Step 1: Start the algorithm. Use a keyword like START or BEGIN.
- 2
START
- 3
Step 2: Prompt the user for the first number and store it. Use a keyword like INPUT or READ.
- 4
OUTPUT 'Enter the first number:'
- 5
INPUT number1
- 6
Step 3: Prompt the user for the second number and store it.
- 7
OUTPUT 'Enter the second number:'
- 8
INPUT number2
- 9
Step 4: Perform the calculation and store the result in a new variable.
- 10
SET total = number1 + number2
- 11
Step 5: Display the final result to the user. Use a keyword like OUTPUT or PRINT.
- 12
OUTPUT 'The total is: ' + total
- 13
Step 6: End the algorithm. Use a keyword like END or STOP.
- 14
END
Recap
- An algorithm is a step-by-step plan to solve a problem.
- Pseudocode is a way of writing an algorithm using structured English.
- Pseudocode helps you plan program logic before you start coding.
- Common pseudocode keywords include INPUT, OUTPUT, SET, IF, ELSE, and END.
- Planning with pseudocode makes coding easier and reduces logic errors.
Quick check
- What is the purpose of using pseudocode in program development?2 marks
- Write a single line of pseudocode to get a user's age and store it in a variable called 'userAge'.1 mark