Python Program To Solve Quadratic Equation

Python Program To Solve Quadratic Equation

Quadratic-Formula-Equation

In algebra, a quadratic equation is any equation that can be rearranged in standard form:

where x represents an unknown, and a, b, and c represent known numbers, where a ≠ 0.

If a = 0, then the equation is linear, not quadratic, as there is no ax^2 term.

 

Quadratic-Root-Equation.png

Above formula, we are going to use to find out the Quadratic Equation Roots.

 

Example

def quadraticEquationSolution(A,B,C):
    D = (B**2)-(4*A*C)
    
    if (D>0):
        print('First Root X1: ',(-B+(D**0.5))/2*A)
        print('Second Root X2: ',(-B-(D**0.5))/2*A)
    elif(D==0):
        print(B**2/2*A)
    else:
        print('Roots Are Imaginary!')

a=1
b=-5
c=6
quadraticEquationSolution(a,b,c)

Output:

First Root X1:  3.0
Second Root X2:  2.0

Leave a comment