Implement the Bisection Method - Implement the Bisection Method

Tell us what’s happening:

why is this test not passing test 8. I am stuck on precision for number less than 1. Please help

Your code so far

def square_root_bisection(number, tolerance=0.01, max_iteration=100):
       if number < 0:
           raise ValueError("Square root of negative number is not defined in real numbers")
       if number == 0 or number == 1:
           print(f"The square root of {number} is {number}")
           return number
       
       low = 0.0
       high = max(1.0, number)
       
       for _ in range(max_iteration):
           mid = (low + high) / 2.0
           print(f"{_} {mid}")
           square_target = mid * mid
           if abs(square_target - number) <= tolerance:
               print(f"square_target {square_target}")
               print(f"The square root of {number} is approximately {mid}")
               return mid
           if square_target > number:
               high = mid
           else:
               low = mid
       
       print(f"Failed to converge within {max_iteration} iterations")
       return None
   

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0

Challenge Information:

Implement the Bisection Method - Implement the Bisection Method

You are close, there’s one detail left. Consider the part of instructions mentioning how the method works and when it should stop.