# Implement the Bisection Method

**URL:** <https://forum.freecodecamp.org/t/implement-the-bisection-method/789114>\
**Category:** Curriculum Help\
**Tags:** python\
**Created:** [May 17, 2026, 3:32pm UTC](https://forum.freecodecamp.org/t/implement-the-bisection-method/789114 "2026-05-17T15:32:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![owenyuandelta](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/owenyuandelta/32/408274_2.png) [@owenyuandelta](https://forum.freecodecamp.org/u/owenyuandelta)\
**Post date:** [May 17, 2026, 3:32pm UTC](https://forum.freecodecamp.org/t/implement-the-bisection-method/789114/1 "2026-05-17T15:32:17Z")

</div>

For some reason in the challenge: Implement the Bisection Method, I cant get past steps 8 and 9.

8. `square_root_bisection(0.001, 1e-7, 50)` should return a number between `0.03162267660168379` and `0.031622876601683794`.

9. `square_root_bisection(0.001, 1e-7, 50)` should print `The square root of 0.001 is approximately X`, where `X` is a number between `0.03162267660168379` and `0.031622876601683794`.

Here is my code:

def square\_root\_bisection(value, tolerance = 0, max\_iter = 0):

```
if value < 0:

    raise ValueError('Square root of negative number is not defined in real numbers')

if value == 0:

    print(f"The square root of {value} is {value}")

    return value

if value == 1:

    print(f"The square root of {value} is {value}")

    return value

low = 0

high = max(1, value)

counter = 0

while (high - low) >= tolerance or counter <= max_iter:

    mid = (low + high) / 2

    

    if abs(value-mid\*\*2) <= tolerance:

        print(f"The square root of {value} is approximately {mid}")

        return mid

    

    elif mid\*\*2 > value:

        high = mid

    

    else:

        low = mid

    counter += 1

print('Failed to converge within 10 iterations')

return None

```

---

<div class="post-metadata">

**Author:** ![dhess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dhess/32/406235_2.png) [@dhess](https://forum.freecodecamp.org/u/dhess)\
**Post date:** [May 17, 2026, 4:20pm UTC](https://forum.freecodecamp.org/t/implement-the-bisection-method/789114/2 "2026-05-17T16:20:51Z")

</div>

Hi there,

> [@owenyuandelta](#):
>
> ```auto
> if abs(value-mid\*\*2) <= tolerance:
> 
> ```

This line is suspect. In your `while` loop, you check `high - low` against the tolerance, but here you are not checking “the difference between the upper and lower bounds” against the tolerance.

Happy coding!

---

<div class="post-metadata">

**Author:** ![onlylibyan](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/onlylibyan/32/356019_2.png) [@onlylibyan](https://forum.freecodecamp.org/u/onlylibyan)\
**Post date:** [May 18, 2026, 5:04pm UTC](https://forum.freecodecamp.org/t/implement-the-bisection-method/789114/3 "2026-05-18T17:04:44Z")

</div>

Thank you, this was very helpful

---

<div class="post-metadata">

**Author:** ![owenyuandelta](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/owenyuandelta/32/408274_2.png) [@owenyuandelta](https://forum.freecodecamp.org/u/owenyuandelta)\
**Post date:** [May 26, 2026, 12:03am UTC](https://forum.freecodecamp.org/t/implement-the-bisection-method/789114/4 "2026-05-26T00:03:18Z")

</div>

Thanks! I changed my code and it worked. But I was wondering why checking the high - low against the tolerance rather the value - mid squared is the correct solution because I thought my way worked too.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [June 23, 2026, 12:03am UTC](https://forum.freecodecamp.org/t/implement-the-bisection-method/789114/5 "2026-06-23T00:03:55Z")

</div>

Closed on June 23, 2026, 12:03am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
