Quadratic equation:
Quadratic equation is made from a Latin term "quadrates" which means square. It is a special type of equation having the form of:
ax2+bx+c=0
Here, "x" is unknown which you have to find and "a", "b", "c" specifies the numbers such that "a" is not equal to 0. If a = 0 then the equation becomes liner not quadratic anymore.
In the equation, a, b and c are called coefficients
Output:
Explanation -
In the first line, we have imported the cmath module and we have defined three variables named a, b, and c which takes input from the user. Then, we calculated the discriminant using the formula. Using the cmath.sqrt() method, we have calculated two solutions and printed the result.
Second Method
We can get the solution of the quadric equation by using direct formula. Let's understand the following example.
Above formula consists of the following cases.
Example -
Output:
Explanation -
In the above code, we have imported the math module and defined the formula to calculate discriminant. We have then defined findRoots function which take three integer values as arguments. Then we have checked the roots using the if-elif-else statement.
need an explanation for this answer? contact us directly to get an explanation for this answer