The Five Steps of Problem Solving
Quick answer A computer supplies no common sense, so you first analyse a problem into Input, Process and Output with its constraints and edge cases, then design an algorithm, code it, test it and debug it - with testing routinely throwing you back to an earlier step.
A computer is fast and it is exact, but it has no common sense. Tell a friend "book my ticket on IRCTC" and they will fill in a hundred small decisions on their own — which train, which class, which date. Tell a computer the same thing and it fills in nothing. It does exactly what the instructions say, in exactly the order they are written, every single time. So the hard part of programming is not typing Python. The hard part is working out the complete, unambiguous list of steps before you type anything.
CBSE splits that work into five steps.
| Step | What you actually do | What it produces |
|---|---|---|
| 1. Analysing the problem | Read the problem and list what is given, what is wanted, and what the limits are | An Input-Process-Output description |
| 2. Developing an algorithm | Write the exact sequence of steps as pseudocode, or draw it as a flowchart | An algorithm — still language-independent |
| 3. Coding | Translate the algorithm into Python | A program (source code) |
| 4. Testing | Run the program on chosen inputs, including nasty ones, and compare with the answer you already know | A pass/fail result for each test case |
| 5. Debugging | Find why a failing case failed, fix it, and test again | A corrected program |
Steps 4 and 5 loop back into step 3, and sometimes all the way back to step 1. If testing shows the algorithm itself was wrong, no amount of fiddling with the code will save it.
Step 1 in detail. Analysing a problem means answering three questions before you write a single line:
- Input — what data is given to me, and in what form?
- Process — what has to be done to that data?
- Output — what exactly has to be shown, and in what form?
Two more questions save you most of the pain later. What are the constraints (marks lie between 0 and 100, an age cannot be negative), and what are the edge cases (zero students, all marks equal, a bill of exactly ₹1000)?
Worked example. Problem: a student wrote five unit tests. Print the total, the average, and PASS if the average is 33 or more, otherwise FAIL.
| Part of the analysis | For this problem |
|---|---|
| Input | Five marks: 72, 65, 88, 54, 91 |
| Process | total = sum of the marks; average = total ÷ 5; compare average with 33 |
| Output | Total, average, and the word PASS or FAIL |
| Constraints | Each mark is 0 to 100; there are exactly five tests |
| Edge cases | All marks 0; average exactly 33; no marks at all |
marks = [72, 65, 88, 54, 91] # INPUT
total = sum(marks) # PROCESS
average = total / len(marks)
if average >= 33:
result = "PASS"
else:
result = "FAIL"
print("Total :", total) # OUTPUT
print("Average :", average)
print("Result :", result)Real output:
Total : 370
Average : 74.0
Result : PASSWhy the analysis step is not optional. Suppose the student was absent for every test, so the list is empty. The same "process" now blows up:
marks = [] # the student was absent for every test
average = sum(marks) / len(marks)
print(average)Real output:
Traceback (most recent call last):
File "avg.py", line 2, in
average = sum(marks) / len(marks)
~~~~~~~~~~~^~~~~~~~~~~~
ZeroDivisionError: division by zeroNothing is wrong with the Python here. The analysis was incomplete — nobody ever decided what an empty list should mean. That decision belongs in step 1, not in step 5.
The computer follows order, not intention. Statements run top to bottom, and a name must exist before it is used.
total = price * qty # used before they exist
price = 60
qty = 3
print(total)Real output:
Traceback (most recent call last):
File "order.py", line 1, in
total = price * qty # used before they exist
^^^^^
NameError: name 'price' is not defined. Did you mean: 'print'?You and I can read those three lines and see what was meant. Python cannot. It reaches line 1, looks for price, finds nothing, and stops. Ordering the steps correctly is part of the algorithm, not an afterthought.
- The five steps are analysing the problem, developing an algorithm, coding, testing and debugging; testing regularly sends you back to coding or even back to the analysis.
- Analysing means writing down Input, Process and Output plus the constraints and edge cases, before any code is typed.
- An algorithm is designed on paper and is independent of any language; coding is only the translation step.
- Most beginner bugs are analysis failures wearing a disguise - an empty list, a zero, a negative value that nobody thought about.
- Python executes statements strictly top to bottom, so using a name before it is assigned raises a NameError rather than being guessed.
