Learn the Bisection Method by Finding the Square Root of a Number - Step 11

Tell us what’s happening:

I am not really understanding where to put the underscore (‘_’), I just need little help help understanding what this is about.

Your code so far

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')

    else:
        low = 0
        high = max(1, square_target)
        root = None
        

# User Editable Region

    for i in range(max_iterations):


# User Editable Region

Your browser information:

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

Challenge Information:

Learn the Bisection Method by Finding the Square Root of a Number - Step 11

1 Like

good attempt but you won’t be using any i variable so you don’t need it. That’s where you use the underscore instead, as a placeholder for a variable you don’t need.

I have tried that but it is not working, I have the underscore in the place of the “i” but it still does not work.

show your code please
what error are you getting?

It says to use ‘_’ as the loop variable. You are using ‘i’ :palm_down_hand: :heart_hands:

I was having the same problem. For me, I played with the indenting and found mine was not where it should have been. I think that is what is going on in your code too.

2 Likes

I believe it wants you to pass the function; adding a pass into the loop and replacing i with an underscore did the job for me :sunflower:

the “for” must be inside the “else”

1 Like

My code right now is this:
for _ in range(max_iterations):
pass

And my error says this:
You should create a for loop to iterate over range(max_iterations) . Use _ as the loop variable.

Ok, I figured it out, I just needed to make another 4 spaces from inside the ‘else’ block.
Thank you for all of your help though.

1 Like