Chapter 19 - Python Quest
Binary Search Missions
Shrink sorted search zones to find exact values, first matches, thresholds, and closest neighbors.
Twenty Questions Flight Log
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
Judge
Ready
Run your code when it feels ready.
