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

Tell us what’s happening:

Can someone please help me understand this scenario and what steps needed to be taken to solve the issue.

Your code so far


# User Editable Region

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


# 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/136.0.0.0 Safari/537.36

Challenge Information:

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

Hi there :waving_hand:,

You’re off to a good start!

However, as the lesson says:

“Begin by creating an if statement to check if square_target is equal to 1.”

Right now, your function starts with checking if the value is negative — which is correct — but you still need to handle the special case when square_target is equal to 1.

ok can you please tell me where to input this line of code is it at the end or at the beginning of the function?

Write the code after the existing if statement.

done but its not taking it should i write it indenting the if statetment of previous one?

Your new if statement should be placed inside the square_root_bisection function.

i am confused i have already placed my new if statement at the end of first if statement and now i have to change it place back to under square_root_bisection?

Plz share you updated code

Hi,
Look at the syntax error in the preview section. You’re missing a :

You got a syntax issue; add a : to fix it. As there’s no content inside if, use pass to avoid any errors.

ok but if i add : then i would have to add a print function inside the if statement what should i put it there?

Lesson only asks for the if statement with the condition that checks if square_target is equal to 1, and to use pass to avoid any errors

ok thanks for the update.

1 Like

Please post code instead of pictures of code. Thanks