Traceback (most recent call last):
File “/Users/PycharmProjects/python/function.py”, line 7, in <module>
elif D > 0:
TypeError: unorderable types: complex() > int()
Я понимаю, что D является комплексным числом и его нельзя сравнить с нулем, в этом случае я не понимаю как D сравнить с нулем.
print("Function ax^2 + bx + c = 0") a = float(input("Enter (a) number: ")) b = float(input("Enter (b) number: ")) c = float(input("Emter (c) number: ")) D = (((b ** 2) - 4 * a * c) ** 0.5) if D == 0: print("D = {}".format(D), "x = {}".format(-b / (2 * a))) elif D > 0: x1 = (-b + ((b ** 2 - 4 * a * c) ** .5)) / (2 * a) x2 = (-b - ((b ** 2 - 4 * a * c) ** .5)) / (2 * a) print("D = {}, D > 0 {}x^2 + {}x + {} = 0".format(D, a, b, c)) print("x1 = {}, x2 = {}".format(x1, x2)) else: print(" D = {}, D < 0 No real roots".format(D))