curriculum/challenges/english/blocks/learn-the-bisection-method-by-finding-the-square-root-of-a-number/65ef198fde24dfb7ff675b42.md
The raise statement allows you to force a specific exception to occur. It consists of the raise keyword followed by the exception type, and enables you to provide a custom error message:
raise ValueError("Invalid value")
When the code above runs, a ValueError is raised and the message "Invalid value" is shown to the user.
If the square_target is less than 0, no real-valued square root can be computed. Therefore, raise a ValueError with the message 'Square root of negative number is not defined in real numbers'. Don't forget to remove the pass keyword.
You should remove the pass keyword.
({
test: () => {
assert.isFalse(runPython(`_Node(_code).find_function("square_root_bisection").find_ifs()[0].find_bodies()[0].has_pass()`))
}
})
You should raise a ValueError with the message 'Square root of negative number is not defined in real numbers' inside the if body.
({
test: () => {
assert(runPython(`_Node(_code).find_function("square_root_bisection").find_ifs()[0].find_bodies()[0].is_equivalent("raise ValueError('Square root of negative number is not defined in real numbers')")`))
}
})
--fcc-editable-region--
def square_root_bisection(square_target, tolerance=1e-7, max_iterations=100):
if square_target < 0:
pass
--fcc-editable-region--