Codington
0 of 6 problems solved • 0%

Exercise prompt

Stop at the Closure

A route planner can stop scanning as soon as it finds a closed segment.

Example

An alarm stops inspecting sensor readings at the first one above its limit.

for reading in [7, 12, 9]: if reading > 10: print("Alarm", reading) break print("Safe", reading) # Safe 7 # Alarm 12

The break exits the loop immediately, so 9 is never inspected. Put any work that should happen only for usable entries after the stop check.

Your task

Complete open_distance(segments). Walk the list with a for loop and total the lengths until the first None, which marks a closure. Distances are nonnegative integers. For [2, 0, 3, None, 8], return 5.