Write a program to solve a quadratic equation ax2 + bx + c = 0. Always check if the discriminant (D)
> 0, then the equations has two roots
= 0, then the equation has one root (two equal roots)
< 0, the equation has no real roots
where D = square root of b2 - 4ac
a = int(input())
b = int(input())
c = int(input())
# a^2 + bx + c = 0
d = b ** 2 - 4 * a * c
if d > 0:
print('x1 =', (-b-sqrt(d)) / (2*a))
print('x2 =', (-b+sqrt(d)) / (2*a))
elif d == 0:
print('x1 = x2 =', -b / (2*a))
else:
print('No roots')
Comments
Leave a comment