2016-07-17 26 views
-2
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) 

您好,我有复杂和int给我一个错误的问题。有针对这个的解决方法吗?提前致谢。类型复杂与int

+1

你有什么问题?你在哪里使用'复杂'?什么是错误? – wallyk

+0

TypeError:unorderable types:complex()

+0

当我输入a = 2,b = 2和c = 2时,结果是一个复数,并给出了我粘贴在上述消息中的错误。 –

回答

0

孔的问题是要实现以决定什么是方程的结果的逻辑....

你假设这是歧视的根源在quadratic equation术语: root_1root_2

,但是这是在告诉你关于实根与否:

(b**2) - 4*a*c) 

被称为判别

并且被计算为

enter image description here

如果这(b**2) - 4*a*c)为正,则平方根是一个实数,但如果表达式为负,那么平方根将产生的假想号码...

enter image description here