Skip to content
Tactiverge

Olympiad · Practice · public practice problem

Cleaning a sonar log

Difficulty 3 of 510 points in 4 partsSuggested time ~18 min (never timed here)

The problem

An ultrasonic sensor can only measure 2 cm to 400 cm. Out-of-range echoes come back as 0.0 or 650.0. A program summarises one log:

readings = [52.0, 51.4, 0.0, 52.6, 650.0, 51.1, 53.3]
valid = []
for r in readings:
    if r >= 2 and r <= 400:
        valid.append(r)
print(len(valid), sum(valid) / len(valid))
  1. Part (a) · 2 points

    What is the first number printed (how many readings are valid)?

    (pure number)Tolerance: exact

  2. Part (b) · 3 points

    What is the mean of the valid readings?

    cmTolerance: ±0.01 cm

  3. Part (c) · 2 points

    What mean would the program print if it forgot the range check and averaged all seven readings?

    cmTolerance: ±0.5 %

  4. Part (d) · 3 points · rubric with 2 criteria

    A teammate rewrites the test as if r >= 2 or r <= 400:. What does the program now do, and which boundary test would catch the bug?

    Written parts stay in your browser. Reveal the worked solution to mark yourself against the rubric.

Checked so far: 0 of 7 automatically marked points, plus 3 for written parts you mark yourself against the rubric. Nothing is saved.

Stuck? Hints, then the worked solution

Written with AI assistance. Review status: technically-checked (answers recomputed independently with units verified by automated tests); not yet reviewed by an educator or judge.