The shape of the lesson
By the end of the lesson, learners can
- Precision matters: Examiners can only award marks for statements a computer could follow.
- Writing a solution: Run the standard methods programs in the lab, then see how the same patterns combine into one full answer to a scenario.
- From flowchart to code, and amending: Fig. 1 is a flowchart; the first program below is the same algorithm in pseudocode.
- Initialise: totals and counts to 0; max low, min high; declare constants.
- Input: prompt, then INPUT; validate with a loop if the question asks.
- Process: choose FOR (known number), WHILE or REPEAT (until a condition).
- Output: results with clear messages, after the loop when they are final.
One picture every idea returns to
An algorithm must be precise: write Score > Target, not "score is bigger than the target". Build a solution from the standard parts: initialise variables, prompt and input, validate, process inside a suitable loop (totalling, counting, max/min), then output clear results. Use meaningful identifiers. To amend an algorithm, keep what works and add or change only the lines needed.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Say it precisely.. The longest questions ask you to write an algorithm for a scenario, or to change one you are given. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Precision matters | Examiners can only award marks for statements a computer could follow. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Writing a solution | Run the standard methods programs in the lab, then see how the same patterns combine into one full answer to a scenario. Project tab 2 of the lab (Standard methods to build with) and let a student drive it while the class predicts. Model the worked example A ticket scenario on the board, one line at a time. | Pairs |
| 21 to 30 min | Teach and check: From flowchart to code, and amending | Fig. 1 is a flowchart; the first program below is the same algorithm in pseudocode. Your turn: With the inputs 8, 3, 7, -1, what does the amended algorithm output? | Corners |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 20 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in From flowchart to code, and amending, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Corners
Put one answer or viewpoint in each corner of the room. Students move to the corner they agree with, justify the choice to a partner there, then hear one voice from each corner before the reveal.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| Describing the algorithm in English sentences earns little or nothing. | Write statements: INPUT, OUTPUT, ←, IF, loops. |
| Put the validation loop inside the customer loop, around the INPUT. | Validating once before the main loop checks only the first customer. |
| When amending, keep the original identifiers and structure. | Adding a whole new loop, or renaming variables, risks breaking the parts that already worked. |
Writing and amending algorithms: worksheet
6 questions, 20 marks. Written in the style of the papers; no past paper question is reproduced.
Write pseudocode to input the times, in seconds, of 8 runners in a race, then output the fastest (smallest) time and the average time.
Write pseudocode that asks the user to guess a secret number stored in Secret. The user keeps guessing until correct. Output "Too high" or "Too low" after each wrong guess, and the number of guesses at the end.
Draw a flowchart for an algorithm that inputs a temperature and outputs "Hot" if it is above 30, otherwise "Not hot".
Write the algorithm in Fig. 1 of this lesson in pseudocode.
Amend the ticket algorithm in this lesson so that it also outputs the largest number of tickets bought by any one customer. State where each new line goes.
A student writes "keep adding the numbers until the user has finished". Explain why this would not gain full marks and rewrite it as pseudocode statements.
Answer key and marking notes
- Initialise Total ← 0 and Fastest to a large value (or the first time).
- FOR Runner ← 1 TO 8 ... NEXT Runner, with a prompt and INPUT Time inside.
- Total ← Total + Time inside the loop.
- IF Time < Fastest THEN Fastest ← Time inside the loop.
- After the loop: Average ← Total / 8; OUTPUT Fastest and Average.
- Guesses ← 0 before the loop; REPEAT ... UNTIL Guess = Secret.
- Inside: prompt, INPUT Guess, Guesses ← Guesses + 1.
- IF Guess > Secret THEN OUTPUT "Too high"; IF Guess < Secret THEN OUTPUT "Too low".
- After the loop: OUTPUT Guesses.
- START and STOP terminators, joined by flow lines.
- INPUT Temperature in an input/output symbol, then a decision Temperature > 30? with Yes and No exits.
- Yes leads to OUTPUT "Hot", No leads to OUTPUT "Not hot" (input/output symbols), both then to STOP.
- Total ← 0 then INPUT Number.
- WHILE Number <> -1 DO, with Total ← Total + Number and INPUT Number inside, ENDWHILE.
- OUTPUT Total after the loop.
- Before the FOR loop: Largest ← 0.
- Inside the FOR loop, after validation: IF Tickets > Largest THEN Largest ← Tickets.
- After the loop: OUTPUT "Largest order: ", Largest.
- It is not precise: there is no input statement, rogue value or assignment a computer could follow.
- e.g. INPUT Number; WHILE Number <> -1 DO; Total ← Total + Number; INPUT Number; ENDWHILE.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
A program must keep asking for a password until the user types the stored one, however many attempts that takes. Which loop is the best choice?
- A
REPEAT ... UNTIL Password = Stored - B
FOR Attempt ← 1 TO 3 ... NEXT Attempt - C
IF Password = Stored THEN ... ENDIF - D
FOR Attempt ← 1 TO 100 ... NEXT Attempt
Minutes holds how many minutes late a student arrived (0 if on time). Which pseudocode adds one to the count of late arrivals only when the student is late?
- A
IF Minutes > 0 THEN Late ← Late + 1 ENDIF - B
IF Minutes > 0 THEN Late ← Late + Minutes ENDIF - C
IF Minutes >= 0 THEN Late ← Late + 1 ENDIF - D
IF the student is late THEN add one ENDIF
The amended algorithm from the lesson is run with the inputs 9, 4, 11, -1. What is output?
Total ← 0
Count ← 0
INPUT Number
WHILE Number <> -1 DO
Total ← Total + Number
Count ← Count + 1
INPUT Number
ENDWHILE
OUTPUT Total
IF Count > 0
THEN
OUTPUT "Average: ", Total / Count
ENDIF- A24, then Average: 8
- B23, then Average: 5.75
- C24, then Average: 6
- D11, then Average: 11
Which is the best identifier for a variable that stores the number of seats sold for a concert?
- A
SeatsSold - B
x - C
Seats Sold - D
2Seats
An algorithm inputs positive numbers until -1 is entered and outputs their total. It must be amended to also output the largest number entered. Which amendment is correct?
- A
Largest ← 0before the loop;IF Number > Largest THEN Largest ← Numberinside it;OUTPUT Largestafter it - B
Largest ← 0inside the loop;IF Number > Largest THEN Largest ← Numberinside it;OUTPUT Largestafter it - C
Largest ← 0before the loop;IF Number < Largest THEN Largest ← Numberinside it;OUTPUT Largestafter it - D
Largest ← 0before the loop;IF Number > Largest THEN Number ← Largestinside it;OUTPUT Largestafter it
The lesson's ticket algorithm is changed to FOR Customer ← 1 TO 4. Each customer's input is validated with a REPEAT loop (1 to 4 tickets), then TotalTickets and FourCount are updated; tickets cost $5.50. The values typed, in order, are 2, 5, 4, 0, 3, 4. What are the money taken and the number of customers who bought 4 tickets?
- A$71.50 and 2
- B$99.00 and 2
- C$60.50 and 1
- D$13.00 and 2
Quiz key
The number of attempts is not known in advance, so a condition-controlled loop is needed; REPEAT ... UNTIL also asks at least once. A FOR loop runs a fixed number of times, so it stops too early (3) or keeps asking after a correct answer (100). An IF statement checks once and does not repeat at all.
Minutes > 0 is true only for a late student, and Late ← Late + 1 counts them. Adding Minutes totals the minutes late instead of counting students. Minutes >= 0 is true for everyone, including students who were on time. An English phrase such as "the student is late" is not precise pseudocode and earns no credit.
9, 4 and 11 are added and counted: Total 24, Count 3, average 8. The rogue value -1 ends the loop before it is processed, so adding and counting it (23 / 4 = 5.75) is wrong, and so is dividing by 4 (6). 11 would be output only if Total and Count were reset on every pass, which they are not: they are set to 0 once, before the loop.
SeatsSold is meaningful and is a single word made of letters. x is legal but says nothing about the data, so it is a poor choice. An identifier cannot contain a space, and it cannot start with a digit, so Seats Sold and 2Seats are not valid identifiers.
Initialising once before the loop, replacing Largest whenever a bigger number arrives and outputting after the loop is the maximum standard method; 0 is a safe start because every number is positive. Resetting Largest inside the loop leaves only the last number. Using < never replaces 0 with a positive number. Number ← Largest assigns the wrong way round, so Largest stays 0.
Customer 1 enters 2. Customer 2 enters 5 (rejected) then 4. Customer 3 enters 0 (rejected) then 3. Customer 4 enters 4. TotalTickets = 2 + 4 + 3 + 4 = 13, so the takings are 13 × 5.50 = $71.50, and two customers bought 4. $99.00 also adds the rejected 5 and 0. $60.50 and 1 ignores the validation and treats the first four values as the four customers. $13.00 is the number of tickets, not the money taken.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.