Python Program - Solve Quadratic Equation

Here's a Python program to solve quadratic equation:

r‮ refe‬to:theitroad.com
import cmath

# function to solve quadratic equation
def quadratic_eq_solver(a, b, c):
    # calculate the discriminant
    disc = (b**2) - (4*a*c)

    # find two solutions
    sol1 = (-b - cmath.sqrt(disc)) / (2*a)
    sol2 = (-b + cmath.sqrt(disc)) / (2*a)

    # return solutions
    return sol1, sol2

# example usage
a = 1
b = 5
c = 6

# call function to solve quadratic equation
sol1, sol2 = quadratic_eq_solver(a, b, c)

# print solutions
print("The solutions are {0} and {1}".format(sol1, sol2))

Output:

The solutions are (-3+0j) and (-2+0j)