[Solved] ValueError: math domain error


Your traceback indicates you are passing a negative number to the math.sqrt() function:

>>> from math import sqrt
>>> sqrt(4.5 - 5.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
>>> sqrt(-1.0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error

Don’t do that. By definition, the square of a number is always positive, so to get the square root again, you must pass in a positive number.

Note that the exception you posted has nothing to do with the code you posted. That code works just fine:

>>> def partE():
...     e = 3 * 10 // 3 + 10 % 3
...     print("e).", e)
... 
>>> partE()
('e).', 11)

0

solved ValueError: math domain error