Implement the Bisection Method - Implement the Bisection Method

Tell us what’s happening:

I looked at other users code and still don’t understand why they have those chunks of code and it ends up working and why. I seem to still have a contextual gap for bisection method coding and I need help on what resources to use to understand bisection and have to context necessary to code properly while understanding it. I only have challenges 1-5 and 21 fuffilled but dont understand what to do. What resources do I use to understand this?

Your code so far

def square_root_bisection(sq_num, tol=0.01, max_it=100):
    if sq_num == 0 or sq_num == 1:
        sqr_rt = sq_num ** 0.5
        print(f'The square root of {sq_num} is {sqr_num}')
    elif sq_num < 0:
        raise ValueError('Square root of negative number is not defined in real numbers')
    else:
        sqr_rt = sq_num ** 0.5
        print(f'The square root of {sq_num} is approximately {sqr_rt}')
  

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Implement the Bisection Method - Implement the Bisection Method

Read the instructions carefully and implement each one.

For example, if the tolerance is 0.01, the bisection method will keep halving the interval until the difference between the upper and lower bounds is less than or equal to 0.01.

Your function does not do this at all?

Your function does not take a group of numbers and cut it in half and examine the top or bottom half?

You could review here:
https://www.freecodecamp.org/learn/python-v9/lecture-searching-and-sorting-algorithms/what-is-binary-search-and-how-does-it-differ-from-linear-search

Or do a google search for an explanation of the bi-section method

For example, if the tolerance is 0.01, the bisection method will keep halving the interval until the difference between the upper and lower bounds is less than or equal to 0.01.

Start your function by defining the upper and lower bounds of where the square root will be found

1 Like