Back to Freecodecamp

Step 8

curriculum/challenges/english/blocks/learn-the-bisection-method-by-finding-the-square-root-of-a-number/65ef1a720d6e65bbb0d22463.md

latest927 B
Original Source

--description--

Next, you are going to work on the cases where the square_target is a positive number apart from 1 or 0.

Create an else clause to handle these cases.

--hints--

Create an else clause and do not forget to add a pass keyword.

js
({
    test: () => 
    {
        assert(runPython(`_Node(_code).find_function("square_root_bisection").find_ifs()[1].find_conditions()[2] == _Node()`))
    }
})

--seed--

--seed-contents--

py
def square_root_bisection(square_target, tolerance=1e-7, max_iterations=100):
    if square_target < 0:
        raise ValueError('Square root of negative number is not defined in real numbers')
    if square_target == 1:
        root = 1
        print(f'The square root of {square_target} is 1')
    elif square_target == 0:
        root = 0
        print(f'The square root of {square_target} is 0')
--fcc-editable-region--


--fcc-editable-region--