my code is giving me some errors Traceback (most recent call last): File "python", line 7, in ValueError: math domain error
import math
a= 3
b= 5
c= 2
d= b^2 -4*a*c
x1 = math.sqrt(d)
print(x1)
my code is giving me some errors Traceback (most recent call last): File "python", line 7, in ValueError: math domain error
import math
a= 3
b= 5
c= 2
d= b^2 -4*a*c
x1 = math.sqrt(d)
print(x1)
Your d
is -17
(You most probably wanted to use **
instead of ^
)
d
is negative when there are no real solutions, therefore its square roor is also not real:
Please also note that b^2
is not bsquared
, it is b xor 2
. for b square
, use b**2
, or b*b
import math
a = 3
b = 5
c = 2
d = b**2 - 4*a*c # Attention, b^2 is not b square, use b**2
if d > 0:
x1 = math.sqrt(d)
print(x1)
else:
print("there are no real roots")