28. Python Program to find the roots of the given Quadratic Equation.
How does this program work?
- In this program you are going to learn about how to find roots of the given quadratic equation using Python.
-
The term b^2-4ac is known as the discriminant of a quadratic equation. The discriminant tells the nature of the roots.
- If discriminant is greater than 0, the roots are real and different.
- If discriminant is equal to 0, the roots are real and equal.
- If discriminant is less than 0, the roots are complex and different.
- In this program, library function sqrt() is used to find the square root of a number.
Here is the code
import cmath
a = 3
b = 7
c = 8
d = (b**2)-(4*a*c)
eq1 = (-b-cmath.sqrt(d))/(2*a)
eq2 = (-b+cmath.sqrt(d))/(2*a)
print("The solutions are: ",eq1,eq2)