Why does inching a guess toward √54321 burn 23 million steps and nearly 20 seconds — and what does that failure push us toward?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Adding 0.1 to itself ten times is the classic way to expose floating-point rounding. The sum is
already computed for you as total. Assign to exact_equal the boolean result of testing whether
total is exactly equal to 1.0.
Hint: == tests for exact equality and produces a boolean (True or False).
Epsilon tolerance in place of equality
Record that stored floats carry a rounding error of roughly 10 to the negative 10, and write the test abs(guess**2 - x) >= epsilon that replaces an equality check.
The sanity-check condition guess**2 <= x
Write the full while loop with both conditions, trace the overshoot in which one increment carries the guess squared from just under x - epsilon to just past x + epsilon, and record the closing if/else report.
Step size traded against running time
Record the run on x = 54321 with epsilon = 0.01 and step 0.0001: about 2.3 million guesses and a failure, then 23 million guesses over roughly 20 seconds at one tenth the step.