...

Chapter 19 - Python Quest

Binary Search Missions

Shrink sorted search zones to find exact values, first matches, thresholds, and closest neighbors.

XP
0Level 1
Stars
0/15quest stars
Combo
0clean runs
Rank
Seed0/160 Python score
Tracing a shrinking binary-search window

Twenty Questions Flight Log

100 XP

A number-finding drone can ask whether its middle guess is too low, too high, or correct. Its flight recorder must save every guess so the pilot can inspect how quickly the search zone shrank.

Write guess_path(low, high, secret) so it returns every integer guess made by binary search, including the final correct guess. low, high, and secret are integers, both ends are included, and secret is guaranteed to be between low and high. Always choose middle with (low + high) // 2.

Sample checks

guess_path(low=1, high=100, secret=73)returns[50,75,62,68,71,73]

Explanation: the inclusive middles are 50, 75, 62, 68, 71, and 73 as each comparison discards the impossible half until the sixth guess matches

guess_path(low=1, high=100, secret=1)returns[50,25,12,6,3,1]

Explanation: every early guess is too large, so high moves left through 49, 24, 11, 5, and 2 before middle finally reaches the first number

Hint

Hints are ready when you want one.

Lesson reference

Review: Watch the possible interval shrink

Your Python

guess_path

Loading editor

Judge

Ready

0/6

Run your code when it feels ready.