Designing an algorithm for a known user's need

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Designing an algorithm for a known user's need

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Maya's problem statement says she needs a way to remember to feed her class fish each day. What should you do FIRST when designing an algorithm for her?
A Read her problem statement and list the steps the solution must do
B Add a loop that repeats forever
2. Which is the better way to build an algorithm for a known user?
A List the steps first, then add decisions and repeats where needed
B Add every decision and loop first, then think about the steps
3. A student is designing a quiz app for Sam. Which one is an INPUT the user gives?
A The app shows Sam his final score
B Sam types in his answer to a question
4. Zara needs her library app to show which books are due back this week. What is the OUTPUT she needs?
A A list of the books due back this week
B The name of the book she types into the search box
5. Your algorithm has to do something different if the user is under 8 years old. What should you add?
A A loop: REPEAT 8 TIMES
B A decision: IF age < 8 THEN ... ELSE ...

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1INPUT: user types their name AREPEAT 5 TIMES: water the plant
2OUTPUT: show 'Bus leaves at 8:15' BIF homework is done THEN play ELSE study
3After listing the steps, add a decision if the user's problem needs a choice CThe steps are in the wrong order. The algorithm shows the answer before it collects the input it needs, so the fix is to ask for the number first.
4Add a repeat when the user's problem needs the same steps again and again DThe algorithm was never tested with the user. The designer should follow the steps with the user and check they solve the problem, then fix any mistakes.
51. Show the answer 2. Ask the user for their number EAn input the user gives to the algorithm, which the steps can then use
6Design the steps. Finish. (never tried with the user) FAn output the user needs, shown to them when the algorithm finishes

Definitions

design an algorithm

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_____ pet OUTPUT "Time to feed " + pet
2.
INPUT homework ______ "Time for a break!"
3.
INPUT minutes __ minutes < 10 THEN OUTPUT "Too short"
4.
______ 3 TIMES OUTPUT "Drink some water"
5.
IF age < 8 THEN OUTPUT "Easy level" ____ OUTPUT "Hard level"

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A INPUT choice FROM Mia
B price ← 0
C IF choice = salad
D price ← 5
E END IF
F OUTPUT price
Question 2
A INPUT laps FROM coach
B count ← 0
C REPEAT UNTIL count = lap
D count ← count + 1
E OUTPUT count
Question 3
A OUTPUT steps to Ravi
B ASK Ravi to try the steps
C NOTE what confuses Ravi
D IGNORE what confuses Ravi
E TEST again with Ravi
Question 4
A INPUT subject FROM Zoe
B INPUT date FROM Zoe
C reminder ← subject + date
D OUTPUT reminder
Question 5
A INPUT weather FROM Ben
B IF weather ← rain THEN
C OUTPUT 'Wear a coat'
D ELSE
E OUTPUT 'Wear a hat'
F END IF

Answer Key

Designing an algorithm for a known user's need
Section A: Quick Questions
Q1
A — Read her problem statement and list the steps the solution must do
Q2
A — List the steps first, then add decisions and repeats where needed
Q3
B — Sam types in his answer to a question
Q4
A — A list of the books due back this week
Q5
B — A decision: IF age < 8 THEN ... ELSE ...
Section B: Match the Pairs
Q1
INPUT: user types their name → An input the user gives to the algorithm, which the steps can then use
Q2
OUTPUT: show 'Bus leaves at 8:15' → An output the user needs, shown to them when the algorithm finishes
Q3
After listing the steps, add a decision if the user's problem needs a choice → IF homework is done THEN play ELSE study
Q4
Add a repeat when the user's problem needs the same steps again and again → REPEAT 5 TIMES: water the plant
Q5
1. Show the answer 2. Ask the user for their number → The steps are in the wrong order. The algorithm shows the answer before it collects the input it needs, so the fix is to ask for the number first.
Q6
Design the steps. Finish. (never tried with the user) → The algorithm was never tested with the user. The designer should follow the steps with the user and check they solve the problem, then fix any mistakes.
Section C: Definitions
Q1
design an algorithm — Start with the user's problem, list the steps the solution must do, then add any decisions and repeats. Think about what the user puts in and needs out, and test the steps with them.
Section D: Fill in the Blanks
Q1
INPUT pet OUTPUT "Time to feed " + pet
Q2
INPUT homework OUTPUT "Time for a break!"
Q3
INPUT minutes IF minutes < 10 THEN OUTPUT "Too short"
Q4
REPEAT 3 TIMES OUTPUT "Drink some water"
Q5
IF age < 8 THEN OUTPUT "Easy level" ELSE OUTPUT "Hard level"
Section E: Spot the Error
Q1
C — An IF decision needs the word THEN after its condition. The line should be IF choice = salad THEN so Mia's lunch price is only changed when she picks salad.
Q2
C — The coach's input is stored in laps, but this line uses lap, a name that was never set up. It should be REPEAT UNTIL count = laps so the loop stops at the number the coach gave.
Q3
D — Testing with the user only helps if you use what you learn. After noting what confuses Ravi, the step should be to FIX the confusing steps, not ignore the problem.
Q4
B — This is a trick check: the correct program has INPUT date FROM Zoe on line 2, because the date is something Zoe gives the solution. Using OUTPUT would show a date instead of collecting it.
Q5
B — A condition compares values, so it needs = and not the assignment arrow ←. It should be IF weather = rain THEN so Ben gets the right advice for the weather.