什么不是我的 python 代码 运行?

What isnt my python code running?

我的代码有一些错误 追溯(最近一次通话): 文件 "python",第 7 行,位于 ValueError:数学域错误

  import math
  a= 3
  b= 5
  c= 2
  d= b^2 -4*a*c
  x1 = math.sqrt(d)
  print(x1)

您的 d-17(您很可能想使用 ** 而不是 ^

What is the root of a negative number?

That is what the exception is saying

d在没有实数解时为负,所以它的平方根也不是实数:
另请注意,b^2 不是 bsquared,而是 b xor 2。对于 b square,使用 b**2,或 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")