Table of Contents
Program to Solve Quadratic Equation in python
- The General formula of quadratic equation ax**2 + bx + c = 0
- Formula to find the discriminant quadratic equation. d = (b**2) – (4*a*c)
- Root x = [-b ± √(b² – 4ac)]/2a
Method 1
Method 2
Method 1
# Use to import complex math module
import cmath
a = 1
b = 6
c = 5
d = (b**2) - (4*a*c)
s1 = (-b-cmath.sqrt(d))/(2*a)
s2 = (-b+cmath.sqrt(d))/(2*a)
print("The first roots is:",s1)
print("The first roots is:",s2)
Method 2
# Use to user input also use import complex math module
import cmath
print("Enter the a value")
a=int(input())
print("Enter the b value")
b=int(input())
print("Enter the c value")
c=int(input())
d = (b**2) - (4*a*c)
s1 = (-b-cmath.sqrt(d))/(2*a)
s2 = (-b+cmath.sqrt(d))/(2*a)
print("The first roots is:",s1)
print("The first roots is:",s2)