Study Guide Instructor view

Totalling, Counting and Finding Extremes

Teaching notes for Lesson 5.6, with controls for presenting it.

Keep this page on your own screen. Share only the lesson window. The lesson window holds no teaching notes, so sharing it cannot show them.

Presenting

  1. Open the lesson in its own window and share that window, not this one.
  2. Use Next and Previous here, or the lesson’s own, to move through the lesson. Next reveals one thing at a time: the next idea, or the answer to the question on screen, then the next step. Previous takes the last reveal back. The line below says what is on screen and what Next will show.
  3. Reveal hints and answers when the class is ready, and reset a demonstration before using it again.

The controls need JavaScript and a browser that supports BroadcastChannel. Without them, open the lesson in presentation mode and use its own controls.

The two windows talk to each other only inside this browser, on this device. Nothing is sent to a server, and no account is needed. A second device (a phone or another tablet) cannot follow the lesson window yet.

Lesson plan

Level
Intermediate
Time
About 75 minutes; the steps below add up to 75

Pupils start with a teacher who hears marks one at a time and must keep track of things between marks, which gives every later pattern a human model: a running total, a tally, a highest so far. They then build totalling, counting, highest and lowest, and the average, each by predicting and tracing before the pattern is stated, and finish with a combined program, a faulty one to repair and a program of their own. The key discipline is where each starting value is set and what it is.

Objectives

  • Write and trace an algorithm that keeps a running total, and say why the total must be set to 0 before the loop
  • Write and trace an algorithm that counts how many values meet a condition
  • Find the highest and lowest of a list of values, and explain how to set the starting values
  • Calculate an average from a total and a count, and guard against dividing by zero
  • Spot and correct mistakes in these algorithms
  • Combine the methods in one program for a given scenario

Before the lesson

  • Mini whiteboards, one per pupil, for predictions and for tallies.
  • Write the marks 12, 7, 15, 9, 13 on small cards. Use them to read out one at a time while a pupil keeps the running total, count and highest on the board.
  • Draw an empty trace table (Mark, Total, Count, Highest, Lowest) on the board ready for step 6.
  • Optional: a tally chart on the board for the count of passes.

Steps

  1. Introduction Opening

    On screen: the lesson’s title, module and number; Next adds its objectives and key terms, as the lesson page lists them; Next again begins the first step.

    Objectives on screen

    • Write and trace an algorithm that keeps a running total, and say why the total must be set to 0 before the loop
    • Write and trace an algorithm that counts how many values meet a condition
    • Find the highest and lowest of a list of values, and explain how to set the starting values
    • Calculate an average from a total and a count, and guard against dividing by zero
    • Spot and correct mistakes in these algorithms
    • Combine the methods in one program for a given scenario

    Purpose: Pupils start with a teacher who hears marks one at a time and must keep track of things between marks, which gives every later pattern a human model: a running total, a tally, a highest so far. They then build totalling, counting, highest and lowest, and the average, each by predicting and tracing before the pattern is stated, and finish with a combined program, a faulty one to repair and a program of their own. The key discipline is where each starting value is set and what it is.

  2. 1. A long list of marks Think 4 min

    Purpose: Pupils work out for themselves what a person must remember while marks arrive one at a time, so that each variable in the later programs has a human reason.

    Ask

    • How could she find the highest mark and the average while the marks are read out one at a time?
    • What has she got to keep track of between one mark and the next?

    Responses to expect

    • A running total and a count
    • The highest mark so far
    • Some say write all the marks down first, which the scenario rules out

    Misconceptions to challenge

    • A learner may believe: “She can look back at all the marks at the end.” Respond: In the scenario the marks are read once; what would she have to keep in her head or on the pad?

    Checking understanding: Pupils write the two or three things on a mini whiteboard; every answer should name a quantity that changes with each mark.

    Depending on the answers

    • If pupils write down all the marks: ask them to imagine the marks are forgotten once heard, as in a program reading INPUT.

    English as an additional language

    • Check total, average and highest; show a list of marks on a card.

    Discussion pause: Thirty seconds of silent thinking, then pairs list the things the teacher keeps on her pad.

    In the lesson window

    • Think it through: Describe how she could find the highest mark and the average while the marks are read out one at a time. What does she have to keep track of between one mark and the next?
  3. 2. Keeping a running total Predict 10 min

    Purpose: Pupils predict a four-round quiz total, say why Total starts at 0, trace it, and see what happens when the reset is moved inside the loop.

    Ask

    • Scores 3, 5, 2 and 6: what is output? Why is the first line needed?
    • If Total ← 0 is the first line inside the loop, what does OUTPUT Total show?

    Responses to expect

    • 16
    • Total needs a starting value of 0 before anything is added
    • Some say 0 or 16 for the moved reset

    Misconceptions to challenge

    • A learner may believe: “The first line is not needed because Total starts at nothing.” Respond: Ask what Total + Score means on the first pass if Total holds nothing sensible.
    • A learner may believe: “Moving the reset into the loop still gives 16 because all the scores are added.” Respond: Trace pass 2: Total is reset to 0 before the 5 is added, so what has happened to the 3?
    • A learner may believe: “The reset gives 0 at the end because Total is zero.” Respond: The scores are still added after each reset; what is the last thing that happens on the final pass?

    On the board or with the pen

    • Write Round, Score and Total columns and fill the totals 3, 8, 10, 16; then redo it with the reset inside the loop: 3, 5, 2, 6 (each pass starts from 0).

    What learners should notice

    • With the reset inside the loop, each total depends on one score only.

    Checking understanding: The reset-total question has three plausible answers: 16 (reset ignored), 0 (reset taken to wipe everything) and 6 (correct).

    Depending on the answers

    • If pupils answer 16: trace the first two passes slowly on the board and ask what Total holds at the start of pass 2.
    • If pupils answer 0: ask them what is added after the reset on the final pass.

    Support

    • Give the trace table with the first row filled in.

    Stretch

    • What if Total started at 10 instead of 0? What would the program output?

    English as an additional language

    • Check running total and reset; mime a ball rolling and picking up more snow.

    In the lesson window

    • Think it through: A team scores 3, 5, 2 and 6 in the four rounds. Predict what the program outputs. Then say why the first line is needed.
    • Apply it: A programmer moves Total ← 0 to be the first line inside the loop, before INPUT Score. The scores are 3, 5, 2 and 6 again. What does OUTPUT Total show after the loop?
  4. 3. Counting how many Discover 11 min

    Purpose: Pupils keep a tally of passes in a list of marks before counting is named, then compare it with totalling and choose the right condition for a boundary mark.

    Ask

    • How many of 62, 45, 50, 38 and 71 pass, and how did you keep track?
    • How is that different from the running total?
    • Which condition counts a mark of exactly 50?

    Responses to expect

    • Three: 62, 50 and 71
    • Add 1 for each pass, rather than the value itself
    • Mark >= 50

    Misconceptions to challenge

    • A learner may believe: “Counting adds the mark each time.” Respond: A count adds 1 each time something happens; the marks are not added.
    • A learner may believe: “Mark > 50 counts 50 as a pass.” Respond: Test 50: is 50 greater than 50?
    • A learner may believe: “Mark = 50 counts all the passes.” Respond: It only counts pupils with exactly 50. What about 62?
    • A learner may believe: “Passes goes up for every mark.” Respond: It goes up only inside the IF; the 45 and 38 rows leave it unchanged.

    On the board or with the pen

    • Draw a tally chart for the five marks, then write the program trace beside it: Pupil, Mark, Mark >= 50?, Passes.

    Follow-up questions

    • How would you count the pupils who got 50 or more and less than 70?

    Checking understanding: The boundary-pass check has three symbol options, and the count trace includes the boundary mark 50 as a fixed point; check that pupils write Yes for it.

    Depending on the answers

    • If pupils choose Mark > 50: put 50 into the condition and read it aloud: is 50 greater than 50?
    • If pupils write 3 straight away: ask them which two marks did not pass and where the program skips them.

    Support

    • Provide the trace table with the Mark >= 50? column filled in.

    Stretch

    • Count the marks that are below 40 in the same program.

    English as an additional language

    • Check tally and pass; show a tally chart with five-bar gates.

    In the lesson window

    • Think it through: How many passed, and how did you keep track as you went along? What is the difference between how you kept track here and in the running total?
    • Check your understanding: The mark 50 is read out. The teacher says it is a pass. Which condition counts it?
  5. 4. Remembering the highest and lowest Discover 12 min

    Purpose: Pupils choose a starting value for the highest and lowest, find out why 0 can fail, and trace a program that starts with the first reading.

    Ask

    • What value would you start with for the highest so far? Does 0 work? Does 0 work for the lowest?
    • What does the program output for Lowest if it starts at 0 on the readings 12, 7, 15, 9, 13?

    Responses to expect

    • The first value, or 0 only if nothing can be negative
    • 0 does not work for the lowest of positive readings
    • 0

    Misconceptions to challenge

    • A learner may believe: “0 is a safe starting value for any maximum or minimum.” Respond: A freezing week has only negative temperatures; the program would report a highest of 0 that never happened.
    • A learner may believe: “Lowest is 7 even when it starts at 0.” Respond: The comparison is Reading < Lowest; is any reading below 0?
    • A learner may believe: “Lowest ends up as the first reading, 12.” Respond: It would only be 12 if it started as 12. What was it set to?
    • A learner may believe: “The loop must start at Day 1.” Respond: Day 1's reading is already read before the loop and used to start Highest and Lowest, so the loop starts at Day 2.

    On the board or with the pen

    • Write Day, Reading, Highest, Lowest and fill row 1 with 12, 12, 12; ask pupils to call out what happens to each column for 7 then 15. Then redo Lowest starting at 0 in a different colour.

    What learners should notice

    • Both Highest and Lowest start with the first reading; each is replaced only by a better one.

    Checking understanding: The lowest-from-zero question: the 7 option is the answer a program should give if started correctly; the 12 option mistakes the first reading for the start. Both are checked against the starting value.

    Depending on the answers

    • If pupils choose 7: ask which line sets the starting value of Lowest, and whether any reading is below it.
    • If pupils are secure: ask for a list of data where starting Highest at 0 would be right, and one where it would be wrong.

    Support

    • Provide the first two rows of the trace and ask pupils to continue.

    Stretch

    • What starting value for Lowest would be safe if every reading is known to be under 100?

    English as an additional language

    • Check maximum, minimum, so far; use a podium image for the highest so far.

    In the lesson window

    • Think it through: You are remembering the highest so far. What value would you start with before the first temperature arrives? Does 0 work? Does 0 work for remembering the lowest?
    • Check your understanding: A programmer sets Lowest ← 0 before the loop, then runs the loop above for the readings 12, 7, 15, 9 and 13. What does the program output for Lowest?
  6. 5. Putting it together: the average Explain 9 min

    Purpose: Pupils find an average by hand, name the two quantities it needs, and see why the division is done after the loop, with a guard against dividing by zero.

    Ask

    • What is the average of 12, 7, 15, 9, 13, and which two quantities did you need?
    • Why is the division after ENDWHILE?
    • What if What happens if no marks are entered?

    Responses to expect

    • 11.2, from a total of 56 and a count of 5
    • Both are only complete once every mark has been read
    • Count is 0 and dividing by it is impossible

    Misconceptions to challenge

    • A learner may believe: “The average can be worked out inside the loop each time.” Respond: Inside the loop it gives the average so far, not the average of all the marks.
    • A learner may believe: “Division is not allowed in a loop.” Respond: Any calculation can go in a loop. The issue is when the totals are complete.
    • A learner may believe: “The -1 is a mark to be added.” Respond: The loop stops when -1 is read, so it is never added.

    On the board or with the pen

    • Write Total, Count and Mark columns for 12, 7, 15, 9, 13 and -1; after the last row draw a line to show the loop ending, then write 56 / 5 = 11.2.

    Checking understanding: The where-divide check: the not-allowed option and the loop-would-not-end option are the common wrong reasons; the correct reason uses the idea of completeness.

    Depending on the answers

    • If pupils think division is not allowed in a loop: ask them to name another calculation in a loop and say why the division is different: it depends on a finished total.
    • If pupils finish early: ask them to trace the program if the first mark typed is -1.

    Support

    • Provide the worked example steps on a card for pupils to follow line by line.

    Stretch

    • Round the average to one decimal place by hand and say where ROUND would go.

    English as an additional language

    • Check mean, average and guard; show 56 divided by 5 as sharing equally.

    In the lesson window

    • Think it through: For the marks 12, 7, 15, 9 and 13, work out the average by hand. Which two quantities did you need, and could you work it out before the last mark had been read?
    • Check your understanding: Why is the division Total / Count placed after ENDWHILE and not inside the loop?
  7. 6. All the methods in one program Apply 11 min

    Purpose: Pupils trace the fuller program that totals, counts and finds extremes, then diagnose a faulty version that adds 1 where it should add the mark.

    Ask

    • What are Total, Count, Highest and Lowest after each mark?
    • Why does Sam's program output 5 instead of 56?

    Responses to expect

    • After 13: Total 56, Count 5, Highest 15, Lowest 7
    • It adds 1 each time, so it counts

    Misconceptions to challenge

    • A learner may believe: “Total ← Total + 1 is right for a total.” Respond: That adds 1 each time, which makes Total a count; the value itself is Mark.
    • A learner may believe: “Setting Total ← 0 inside the loop would fix it.” Respond: That resets it each pass, which is worse.
    • A learner may believe: “The -1 is added to the total.” Respond: The loop ends when -1 is read, so it never reaches Total.
    • A learner may believe: “Highest and Lowest start at 0.” Respond: Here they start with the first mark, as the trace shows in the first row.

    On the board or with the pen

    • Fill the five-row trace live with all four variables; beside it write Sam's loop and show 1, 2, 3, 4, 5 for Total.

    Checking understanding: The trace table checks that pupils can update four variables per pass; Sam's question diagnoses totalling versus counting.

    Depending on the answers

    • If pupils pick the reset option: ask which line updates Total and which updates Count, and compare them.
    • If pupils trace slowly: pair them so that one reads each line aloud and the other updates the board.

    Support

    • Provide the trace table with the Total and Count columns filled in so that pupils focus on Highest and Lowest.

    Stretch

    • Add a line that counts how many marks are above the average. Why must it come after the loop?

    English as an additional language

    • Say each variable name aloud as it changes: Total, Count, Highest, Lowest.

    In the lesson window

    • Apply it: Why does Sam’s program output a total of 5 instead of 56?
  8. 7. Write one yourself Apply 10 min

    Purpose: Pupils write a rainfall program that totals, counts rainy days and finds the highest, and justify a safe starting value.

    Ask

    • Write the program for seven readings: total rainfall, days on which it rained, and highest reading.
    • What do you start the highest with, and why is it safe here?

    Responses to expect

    • A FOR loop of 7 with Total, RainyDays and Highest set to 0 before it
    • 0 is safe because rainfall is never negative

    Misconceptions to challenge

    • A learner may believe: “RainyDays counts the rainfall in millimetres.” Respond: It counts days: add 1 when the reading is above 0.
    • A learner may believe: “Initial values belong inside the loop.” Respond: They are set before the loop; inside they would be reset each day.
    • A learner may believe: “A WHILE loop is needed.” Respond: The number of readings is exactly seven, so a FOR loop fits.

    On the board or with the pen

    • Write the three variables on the board and draw a box around the three lines that go before the loop.

    Checking understanding: Collect the written programs: look for the three starting values before the loop, the FOR loop header, and the use of Rainfall > 0 for the count.

    Depending on the answers

    • If pupils start the variables inside the loop: ask them to trace two readings and compare the output with the expected total.
    • If pupils are quick: ask them to add the lowest reading and say why Lowest cannot start at 0 here.

    Support

    • Provide the starting lines (Total, RainyDays, Highest) and ask pupils to write the loop.

    Stretch

    • Output the average rainfall for the seven days, and only the rainy days average, as a second figure.

    In the lesson window

    • Think it through: Write pseudocode that inputs the seven readings and outputs the total rainfall, the number of days on which it rained (a reading above 0) and the highest reading. Say what you start the highest reading with and why that is safe here.
  9. 8. Show what you know Consolidate 8 min

    Purpose: Pupils explain how to tell a total, a count and a maximum apart, and choose the algorithm for a library average, before the summary.

    Ask

    • Explain total, count and maximum with the same list of marks. Where is each starting value set?
    • For 30 pupils' counts of borrowed books, which description of the average algorithm is best?

    Responses to expect

    • A total adds the mark, a count adds 1, a maximum replaces when bigger
    • A FOR loop of 30 passes, total set to 0 before it, division after it

    Misconceptions to challenge

    • A learner may believe: “Total is reset each pass.” Respond: Starting values are set before the loop, never inside it.
    • A learner may believe: “The division goes inside the loop each time.” Respond: Inside the loop it gives the average so far; calculate after the loop.
    • A learner may believe: “A counter is always needed for an average.” Respond: When the count is always 30, dividing by 30 is enough.

    Checking understanding: Collect the explanations: the best use the same marks for all three and give a starting value for each.

    Depending on the answers

    • If pupils choose the WHILE loop with division inside it: ask them what the program would output on the first pass and whether that is the average of all 30.
    • If several are unsure of where starting values go: begin the next lesson by tracing a program where Total ← 0 has been moved inside the loop.

    In the lesson window

    • Think it through: Explain to a friend how to tell a total, a count and a maximum apart, using the same list of marks. Say where each starting value is set and what it is.
    • Apply it: A fictional library wants the average number of books borrowed per pupil on a day, from a list of 30 pupils’ counts. The number of pupils is always exactly 30. Which description of the algorithm is best?
  10. Lesson recap Closing

    On screen: the lesson’s objectives again; Next adds the closing question, which asks the class to explain each one in their own words without looking back. It says nothing about what anyone has learnt: use the answers to decide what to revisit.

    Points to listen for

    • Totalling adds the value to a running total set to 0 before the loop.
    • Counting adds 1 each time something happens, usually inside an IF.
    • For the highest and lowest, start with the first value and replace when a better one arrives; 0 is a common wrong start.
    • The average is total divided by count, worked out after the loop and only if the count is above 0.
    • Common faults: resetting inside the loop, adding 1 for the value, wrong starting value, averaging too early.

Consolidation

  • Totalling adds the value to a running total set to 0 before the loop.
  • Counting adds 1 each time something happens, usually inside an IF.
  • For the highest and lowest, start with the first value and replace when a better one arrives; 0 is a common wrong start.
  • The average is total divided by count, worked out after the loop and only if the count is above 0.
  • Common faults: resetting inside the loop, adding 1 for the value, wrong starting value, averaging too early.