# Solve the quadratic equation ax**2 + bx + c = 0
# import complex math module
import cmath
a = int(input("Enter the value of a:"))
b = int(input("Enter the value of b:"))
c = int(input("Enter the value of c:"))
# calculate the discriminant
d = (b**2) - (4*a*c)
if d>0:
# find two solutions
r1 = (-b-cmath.sqrt(d))/(2*a)
r2 = (-b+cmath.sqrt(d))/(2*a)
print('The real roots are {0} and {1}'.format(r1,r2))
elif d==0:
r1 = -b/(2*a)
r2 = -b/(2*a)
print('The roots are equal {0} and {1} '.format(r1,r2))
else:
print('The roots are imaginary')
0 Comments