Week 6 · Lesson 5 · 55 minutes

Finish the sensor log tool

Connect tested functions and show evidence that the tool meets its brief.

Planned lesson. Follow your teacher’s teaching order.

Source workbook pages: 40.

Resources

Vocabulary

Vocabulary
requirement: Something the tool must do; evidence: A result that supports a claim; modular: Split into named parts with clear jobs
55-minute lesson sequence
  1. 0–5 · Answer the retrieval alone. Compare one reason.
  2. 5–15 · Teacher models the example. Students predict each next step.
  3. 15–40 · Build, trace and test the main tasks. Work alone first; compare after a checkpoint.
  4. 40–50 · Check results. Explain a test and repair one error. Use the extension only if ready.
  5. 50–55 · Complete the exit alone. Save the evidence for the next lesson.

Try before notes

Choose modes for input readings, a fresh summary and a running check history.

Build the idea

Integration connects small tested functions into one complete tool. Give each function a clear contract: its inputs, returned result or file effect, and assumptions. A reader should not unexpectedly overwrite the source file.

Trace the data path end to end: file to list, list to analysis, analysis to report. Then verify that the report exists, has the right format and contains the correct values. Test the original source remains unchanged.

Evidence needs input, expected result, actual result and a judgement. A failure record is useful if it identifies what differed and what you changed. Demonstrate one test alone so both learners can show independent understanding.

read file → list → count + search → write summary
                                  → append history
read back → compare with prediction

See the method

A test needs input, expected result, actual result and a decision. Example: input [25], limit 25; expected count=1 and high=1; actual report count=1 and high=1; pass. A screenshot of the code alone does not show that the output is correct.

values = [25]
write_summary("single_summary.txt", values, 25)
with open("single_summary.txt", "r", encoding="utf-8") as report:
    print(report.read())

Predict then reveal

A separate demo list is [5,9,9], limit 9. Predict total reading count and high count before integrating functions.

Reveal reasoning

There are three readings. Two are at least 9, including equality. A report contract using count and high would therefore require count=3 and high=2.

The report is correct but the input file is now empty. Does the tool pass a requirement to leave input unchanged?

Reveal reasoning

No. Output correctness is only one requirement. The input-preservation requirement failed. Inspect filenames and modes; writing to the source path with w is a likely cause to test, not a conclusion to assume without evidence.

Work one step together

Read the first task. Each learner predicts the first step privately. Compare the method, then complete one intermediate row or one code iteration together. Do not display a finished workbook answer.

Practice

  1. Finish one program. It must read readings.txt, ignore blank lines, count all readings, count readings at least 25, replace summary.txt, and append one check-history line. Use functions. Do not change readings.txt. Put your own initials in a code comment, not in the data.

Your turn

Complete the remaining steps of task 1 alone, then the next tasks. Predict before running code. Save your own evidence before comparing.

Practice

  1. Finish one program. It must read readings.txt, ignore blank lines, count all readings, count readings at least 25, replace summary.txt, and append one check-history line. Use functions. Do not change readings.txt. Put your own initials in a code comment, not in the data.
  2. Run three tests: the original four readings; a file with one reading 25; an empty file. Use separate filenames or restore the original safely. Record the two expected report lines, the actual lines and pass or fix. Demonstrate one test without your partner helping.
  3. Write a short handover: input format; output files; one limitation; one benefit of using functions. Keep it to four clear sentences.

Check and explain

Passing one output test does not show that every requirement was met.

Point to the first step, row, condition or requirement that supports your answer. If results differ, find the first different state and repair one cause.

Show what you know

Which saved result proves that the empty-file case works?

HL challenge when ready

Add a report line for the first high index. What must it show for an empty file?

Week 6 homework

Show working. Keep code and output. Stop at 25 minutes and mark where you reached.

  1. Without running code first, predict the report for a new file containing 24, 25, 26, a blank line and 19. Use limit 25. Then, if a computer is available, test and compare. Otherwise trace the function on paper.
  2. A check history already has three lines. A program appends one line each run. It runs twice. How many lines are there? What would change if it used w each time?
  3. Write one test that catches > used instead of >= at limit 25. State the input and expected answer.

Source workbook pages: 41.

Weekly homework (Word)

Python practice · two short prompts

Spend about 3 minutes on each during practice time. Predict, run, change one thing, then explain. These prompts do not add homework.

A starter is runnable code to explore or complete. If the playground restores your saved code, the linked starter is selected in Example: use Load example when ready. Download your work before confirming replacement.

Prompt 1

Complete the summary function and try an empty input.

No imports needed.

Hint and starter code

This starter accepts non-negative digit strings only. Explain that limit before extending it to signed values.

# This starter accepts non-negative digit strings only.
def count_valid(lines):
    count = 0
    for line in lines:
        if line.strip().isdigit():
            count += 1
    return count

print(count_valid(["24", "bad", "27"]))
print(count_valid([]))
Open this starter in Python playground →
Prompt 2

Build a small test table for a summary function using synthetic data.

No imports needed.

Hint and starter code

Synthetic data is invented for testing, not claimed as a real sensor observation.

# Synthetic data is invented for testing, not claimed as a real sensor observation.
def count_lines(text):
    return len(text.splitlines())

tests = [("", 0), ("a\nb", 2)]
for text, expected in tests:
    print(count_lines(text) == expected)
Open this starter in Python playground →