Exercise: Raise a Custom Exception
Bartosz Zaczyński RP Team on June 27, 2026
@DimaG, your f-string is fine. f"Value must be non-negative: {n}" produces the exact same message as the solution’s "Value must be non-negative: " + str(n), and it even satisfies the bonus check that looks for the number in the message. So that’s not what’s tripping you up.
The real culprit is the four lines at the bottom:
print(calculate_square_root(9))
print(calculate_square_root(0))
print(calculate_square_root(5))
print(calculate_square_root(-1))
That last call, calculate_square_root(-1), raises NegativeValueError on purpose (raising on negative input is exactly what the exercise asks the function to do). The catch is that this call runs at the top level of your file. When the checker grades your work, it imports your file as a module, runs everything at the top level, and only then runs the tests against your function. Because calculate_square_root(-1) raises an uncaught exception during that import, your file never finishes loading, so the checker never reaches the tests. They all come back as errors even though the function itself is correct.
You actually saw this in VS Code too. Your output was something like:
3.0
0.0
2.23606797749979
Traceback (most recent call last):
...
NegativeValueError: Value must be non-negative: -1
That traceback at the end is your raise doing its job, but it also means the script stopped with an error on the final line.
The exercise only needs the function definition, so removing those four print() lines will get you a pass. If you like keeping a few calls around to experiment, tuck them behind a main guard so they only run when you run the file yourself, not when the checker imports it:
if __name__ == "__main__":
print(calculate_square_root(9))
print(calculate_square_root(-1))
(If you want a refresher on that pattern, see What Does if __name__ == “__main__” Do in Python?.)
Hope that clears it up 🙂
Become a Member to join the conversation.

DimaG on June 24, 2026
If you compare this code to the solution, the only difference is that I used f-string formatted message in the custom exception. Why I am getting punished for it? I ran this code in VS Code and I got exactly what is being requested.