OCR H446, section 2.1.3 (a)
Thinking procedurally means working out the steps needed to solve a problem. Before you can plan the steps, you must understand the problem, which means identifying its components.
What are the components of a problem?
Read the problem carefully and pick out:
| Component | Question to ask |
|---|---|
| Goal | What must the solution achieve? |
| Inputs | What data goes in, and where from? (2.1.2 (a)) |
| Outputs | What must be produced, and in what form? |
| Data to store | What must be remembered between steps or between runs? |
| Rules and processes | What calculations, decisions or repeated actions are needed? |
| Constraints | What limits apply: time, memory, cost, hardware, laws? |
| Users | Who will use it, and what do they need? |
| Assumptions | What can safely be taken for granted? |
| Sub-problems | Which smaller problems is it made of? |
A method
- Read the problem more than once.
- Underline the nouns (candidates for data) and the verbs (candidates for actions).
- Write the goal in one sentence.
- List the inputs and outputs.
- List the rules the problem states.
- Note any constraints and assumptions.
- Split the problem into smaller parts (2.2.2 (c)).
Worked example
Problem: A cinema sells tickets. Adult tickets cost £9 and child tickets cost £6. A group booking of 10 or more tickets gets 15% off the total. The customer enters how many of each ticket they want, and the system shows the total price. A booking cannot be for more than 40 tickets.
| Component | Found in the problem |
|---|---|
| Goal | Work out and show the total price of a booking |
| Inputs | Number of adult tickets; number of child tickets |
| Outputs | The total price |
| Data | The two prices (constants): £9 and £6; the discount rate 15% |
| Rules | Total = adults × 9 + children × 6; if the number of tickets is 10 or more, take off 15% |
| Constraints | At least 1 and at most 40 tickets in total (a booking must have at least one ticket) |
| Validation needed | Whole numbers; not negative; total from 1 to 40 |
| Sub-problems | Get valid input; calculate the total; apply the discount; display the result |
Having done this, the solution is ready to be planned (see 2.1.3 (b)). Notice that the problem doesn't mention validation in detail, but the constraint tells us it is needed.
ADULT, CHILD = 9, 6
DISCOUNT = 0.15
MAX_TICKETS = 40
adults = int(input("Adult tickets: "))
children = int(input("Child tickets: "))
tickets = adults + children
if adults < 0 or children < 0 or tickets < 1 or tickets > MAX_TICKETS:
print("Invalid booking")
else:
total = adults * ADULT + children * CHILD
if tickets >= 10:
total = total * (1 - DISCOUNT)
print(f"Total: £{total:.2f}")
Why this step matters
- A solution built on a misunderstood problem is wrong however well it's coded.
- Finding constraints and assumptions early avoids rework.
- A clear list of components can be checked with the client.
- It gives a checklist for testing later.
Exam tip: if a question describes a scenario and asks for the components, work through it systematically: inputs, outputs, data, rules, constraints. Use details from the scenario, not generic statements.
Check yourself
Name four components you should identify when analysing a problem
Any four of: the goal, inputs, outputs, data to store, rules or processes, constraints, users, assumptions, sub-problems.
Why is it important to identify the components of a problem before designing a solution?
A solution built on a misunderstood problem will be wrong, and identifying components early finds missing information and constraints before time is spent coding.
In the cinema example, what is a constraint?
A booking can't be for more than 40 tickets.
What can underlining the nouns and verbs of a problem statement help you find?
Nouns suggest the data and items involved. Verbs suggest the actions or processes required.