I wrote this code
def partE():e = 3 * 10 // 3 + 10 % 3print("e).", e)partE()
and python comes back with this error message when I try to run it. I do not understand why. Can someone please explain? Thank you so much!
Traceback (most recent call last):File "C:/Users/Crisa/PycharmProjects/untitled/homeworkchap3.py", line 30, in <module>partD()File "C:/Users/Crisa/PycharmProjects/untitled/homeworkchap3.py", line 27, in partDd = sqrt(4.5 - 5.0) + 7 * 3
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)