GoalPut the five steps of solving a problem in order and say which skill each step uses.
New words
input · the data given to a solution when it startsoutput · the result a solution shows or gives backcode · the algorithm written in a programming languagetesting · running the solution on cases whose answers you already know
Explanation
A problem becomes a working program in five steps. Step 1, understand the problem: say in your own words what is asked, and split it into parts. This uses decomposition. Step 2, find the inputs and the outputs: what do we start with, and what must we get? This uses abstraction, because only the important facts count. Step 3, write the steps, the algorithm; here pattern recognition helps if you solved a similar problem before. Step 4, turn the steps into code in a language such as Python. Step 5, test the solution on cases where you already know the answer. If a test fails, go back to the step where the slip began. The steps are not a one-way road: careful programmers return to an earlier step again and again.
1 Understand the problem→2 Inputs and outputs→3 Write the steps→4 Write the code→5 Test
Worked examples
Step
What we write
1 Understand
find the cost of 3 notebooks
2 Inputs, output
price, number; cost
3 Steps
cost = price × number
5 Test
price 5, number 3 → 15
Problem: a shop sells notebooks at the same price each. How much do 3 notebooks cost? Step 1: find the total cost. Step 2: inputs are the price and the number of notebooks, the output is the cost. Step 3: multiply. Step 5: with a price of 5 and 3 notebooks the answer must be 15.
test: 4 and 9 shows 5→back to Step 4→change - into +→test again: 13
Sami wants his program to add 4 and 9, but the screen shows 5. The test failed. He reads his steps and sees that the code subtracts. He goes back to Step 4, changes the minus into a plus and tests again. Now the screen shows 13.
Class activity
Take the problem “find the area of a rectangular poster”. Write the five steps on paper: what is asked, the inputs and the output, the steps, and one test with numbers you choose. You do not need a device.
Practice
1
What is the first step in solving a problem?
Understand the problem.
2
In which step do we decide that a poster problem needs a length, a width and one result?
In Step 2, inputs and outputs.
3
A test fails. What should you do?
Go back to the step where the slip began, fix it and test again.
4
Why do we test with numbers whose answer we already know?
Because we can compare the program’s answer with the right answer.