Python Program to Solve Quadratic Equation

Quadratic equation: ax2 + bx + c = 0 where a, b, and c are coefficients of real numbers and a ≠ 0

Quadratic equation formula $$ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$

1# import complex math module 2import cmath 3a = 10 4b = 5 5c = 20 6 7# calculate the discriminant 8d = (b**2) - (4*a*c) 9 10# find two solutions, based on the formula 11num1 = (-b-cmath.sqrt(d))/(2*a) 12num2 = (-b+cmath.sqrt(d))/(2*a) 13print(f'The solution are {num1} and {num2}')

Output:

1The solution are (-0.25-1.3919410907075054j) and (-0.25+1.3919410907075054j)