Skip to content
Tactiverge

Olympiad · Practice · public practice problem

The loop that never ends

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

The problem

A drone simulator models battery level like this:

level = 100.0      # percent
minutes = 0
while level > 30:
    level = level * 0.9
    minutes = minutes + 1
print(minutes, round(level, 2))

A second program tries to step time in tenths of a second:

t = 0.0
while t != 1.0:
    t = t + 0.1
  1. Part (a) · 3 points

    What value of minutes does the first program print?

    (pure number)Tolerance: exact

  2. Part (b) · 3 points

    What battery level does it print?

    %Tolerance: ±0.01 %

  3. Part (c) · 2 points

    What happens when the second program runs?

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

    Rewrite the second loop's condition so it is safe, and explain why your version works.

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

Checked so far: 0 of 8 automatically marked points, plus 2 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.