【发布时间】:2016-11-20 08:29:57
【问题描述】:
a = int(input("Please enter the value of a: "))
b = int(input("Please enter the value of b: "))
c = int(input("Please enter the value of c: "))
root_1 = (-b + ((b**2) - 4*a*c)**0.5) / 2*a
root_2 = (-b - ((b**2) - 4*a*c)**0.5) / 2*a
if root_1 < 0 or root_2 < 0:
root = "No real roots"
elif root_1 > 0 or root_2 > 0:
root = "Two real roots"
elif root_1 == 0 or root_2 == 0:
root = "One real root"
print("The values you entered have", root)
您好,我遇到了 complex 和 int 的问题,这给了我一个错误。这个问题有方法解决吗?提前致谢。
【问题讨论】:
-
你有什么问题?你在哪里使用
complex?错误是什么? -
TypeError: unorderable types: complex()
-
当我输入 a=2、b =2 和 c=2 时,结果是一个复数,并给出了我在上述消息中粘贴的错误。
-
你应该检查
b^2 - 4*a*c是否大于0,而不是根。 -
好的,谢谢。我会试一试的。(我应该知道的)