How does wrapping a working bisection-root loop in a function that returns its answer let you reuse it to brute-force a brand-new counting problem?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Bisection improves its guess by jumping to the midpoint of the current low and high endpoints. Wrap that single step in a function that returns the new guess (so a caller can reuse the value — don't print it).
Name the function next_guess and give it two inputs, low and high.
bisection_root(x) wrapping the bisection loop
Write the definition with epsilon = 0.01, the low and high endpoints, the while test on the gap between the guess squared and x, and the final return, with bisection_root(4) as 2.0.
A number-line picture drawn before coding
Draw the number line with n marked and a band of plus or minus epsilon around it, and list 99, 100, 101 and 102 as the matches for n = 10, epsilon = 0.1.
Brute-force counting with count_numbers_with_sqrt_close_to
Write the loop count = 0, for i in range(n**3), sqrt = bisection_root(i), if abs(n - sqrt) < epsilon: count += 1, return count, and record the output 4.
Choosing the search bound, and an early exit
Record that n**2 misses 100, 101 and 102 while n**4 also serves, that a band of 10 plus or minus 1 gives 40 matches, and sketch the early-stopping flag.